php curl作为普通用户而不是像机器人一样

时间:2011-10-31 12:45:28

标签: php curl

我正在使用php curl来获取页面。但是,许多网站似乎阻止卷曲,可能是由于它发送的标头/用户代理。任何人都有一个样本卷曲标题,可以模拟普通的浏览器吗?

这是我使用的当前标头:

    $headers[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png, image/gif, image/x-bitmap, image/jpeg, image/pjpeg, *;q=0.5";
    $headers[] = "Cache-Control: max-age=0";
    $headers[] = "Connection: keep-alive";
    $headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $headers[] = "Accept-Language: en-us,en;q=0.5";
    $headers[] = "Pragma: ";
    $headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';

和用户代理:

'Mozilla/6.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';

2 个答案:

答案 0 :(得分:0)

您确定正确设置了user_agent吗?

curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/6.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)'); 

如果是这样,那么我建议您的查询可能存在其他问题而不是用户代理过滤 - 您到底遇到了什么问题?

答案 1 :(得分:0)

下载fiddler Web代理并验证您发送的内容与常规浏览器相同。当您使用fiddler和PHP时,请务必设置:

curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');

也可能涉及到cookie,你忽视了。

相关问题