我自己编了一段简单的php代码,实现如下功能:采集www.weather.com.cn的一个报道杭州天气的页面,并原样输出,可就是采集不到,,,不知是什么原因,大家帮分析下代码如下:
<?php
$url="http://www.weather.com.cn/html/weather/101210101.shtml";
$fcontents=file_get_contents($url);
echo $fcontents;
?>我把上面的代码中的http://www.weather.com.cn/html/weather/101210101.shtml换成 http://ent.163.com/09/0511/10/591CBR5C00031NJO.html采集网易的一个新闻页面却成功了,搞不懂是怎么回事??大家帮分析下
<?php
$url="http://www.weather.com.cn/html/weather/101210101.shtml";
$fcontents=file_get_contents($url);
echo $fcontents;
?>我把上面的代码中的http://www.weather.com.cn/html/weather/101210101.shtml换成 http://ent.163.com/09/0511/10/591CBR5C00031NJO.html采集网易的一个新闻页面却成功了,搞不懂是怎么回事??大家帮分析下
<?php
$context=array('http' => array ('header'=> 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)', ),);
$xcontext = stream_context_create($context);$url="http://www.weather.com.cn/html/weather/101210101.shtml";
$fcontents=file_get_contents($url, FALSE, $xcontext);
echo $fcontents;
exit;
?>