我正在抓取一个使用以下代码的网站
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。它也显示了类似的错误。
$url= 'https://example.com';
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$response = file_get_contents($url, false, stream_context_create($arrContextOptions));
一个建议,你可以用CURL代替…