file_get_contents伪造user_agent 方法如下:
ini_set('user_agent','Mozilla/4.0 (compatibleMSIE 6.0Windows NT 5.1SV1.NET CLR 2.0.50727http://www.baidu.com)')
curl伪造user_agent的方法:
curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatibleMSIE 6.0Windows NT 5.1SV1.NET CLR 2.0.50727http://www.baidu.com)')
附带上curl的完整函数方法:
function curl_get_file_contents($URL)
{
$c = curl_init()
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1)
//curl_setopt($c, CURLOPT_HEADER, 1)//输出远程服务器的header信息
curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatibleMSIE 6.0Windows NT 5.1SV1.NET CLR 2.0.50727http://www.baidu.com)')
curl_setopt($c, CURLOPT_URL, $URL)
$contents = curl_exec($c)
curl_close($c)
if ($contents) {return $contents}
else {return FALSE}
}
这样就可以抓取了,user_agent是可以自己修改的。
应该是这个模板预设了UA估计是考虑到UA一般情况很少会用到,所以所以用了默认的
你可以去模板里搜对$_SERVER['HTTP_USER_AGENT']设置的地方,注释掉就行了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)