刮板php返回一个空白页面

use*_*840 5 php file-get-contents str-replace

我是php新手,我已经制作了一个scraper.php页面,您可以从" http://www.weather-forecast.com "中查找任何特定城市的天气信息.
我正在跟随教师,我无法理解为什么我的代码返回一个空白页面,它应该只返回一个简短的3天预测

无论如何......这是我的代码

<?php
$city=$_GET['city'];
$city=str_replace(" ","",$city);
$contents=file_get_contents("http://www.weather-forecast.com/locations/".$city."/forecasts/latest");
preg_match('/3 Day Weather Forest Summary:<\/b>
<span class="phrase">(.*?)</span>',$contents, $matches);
echo $matches[1];
?>
Run Code Online (Sandbox Code Playgroud)

Cap*_*nch -1

尝试遵循这个问题:

我如何模拟获取请求,就像网络浏览器一样

得到你正在寻找的东西。

解释:

file_get_contents()将为您提供静态页面内容。

您在浏览器中实际看到的内容是由 HTML/CSS/JS 生成的,并且不会通过该file_get_contents()功能看到。

当我尝试直接从浏览器浏览该网址时

(例如:纽约

并打开页面作为源,搜索:“3 Day Weather Forest Summary:”。

我没有得到任何结果,所以我假设这是你的问题。