抱歉,无法获取此URL的html源代码:http : //www.picbear.com/tag/ok ;
我总是得到带有[“ Hello Stranger”]消息的空白页。
如果我使用Chrome的工具,没有问题。
我一直使用file_get_contents
或php_simple_html
没有问题的DOM解析器。
由于提供者的限制,我无法访问php.ini,但应该没问题。
帮助任何人?谢谢。
$url = "http://www.picbear.com/tag/ok";
$html = file_get_contents($url);
echo $html;
只需添加User-Agent
标题:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://picbear.com/tag/ok",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" // Here we add the header
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句