【发布时间】:2016-08-08 03:52:38
【问题描述】:
我正在使用以下代码抓取网站
require 'simple_html_dom.php';
$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
$context = stream_context_create($opts);
$header = file_get_contents('http://www.cinnetwork.org',false,$context);
print_r($header);
此代码在 phpfiddle 中正常工作。但是当我从我的服务器上使用它时,它会说
警告:file_get_contents(http://www.cinnetwork.org):打开失败 流:连接超时
我也尝试过使用 curl。它也显示了类似的错误。
【问题讨论】:
-
配置
allow_url_fopen是否开启? -
allow_url_fopen 已开启
-
该代码适用于其他网站。
-
听起来他们在阻止你。尝试使用代理。
标签: php curl simple-html-dom