目标网页shenyang.liebiao.com/qitashenghuo/55349766.html注意以下方法都不行注意以下方法都不行file_get_contentsfunctioncurlGetHtml($url){$userAgent='Mozilla/4.0(compatible;M...
目标网页
shenyang.liebiao.com/qitashenghuo/55349766.html
注意以下方法都不行
注意以下方法都不行
file_get_contents
function curlGetHtml($url){
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)';//模仿IE浏览器
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8')); //构造IP
curl_setopt($ch, CURLOPT_REFERER, 'http://www.baidu.com/');// 设置选项,来源页,这意味着可以伪造referer达到某种目的
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); //是否显示内容 1 不显示;0 显示(默认)
curl_setopt($ch, CURLOPT_TIMEOUT, 10); //延续多少秒
$html = curl_exec($ch);
curl_close($ch);
if (!$html)
{
$html = false;
}
return $html;
}
展开