我用php的函数fsockopen和fwrite,fgets等命令可直接获得http://www.baidu.com主页的内容,但却不能获得http://www.baidu.com/s?wd=音箱&pn=20的内容,甚是苦闷,觉得是百度做了防范了,但奇怪的是我将浏览器中所有的缓存和cookie都清除掉了,直接用地址栏访问http://www.baidu.com/s?wd=音箱&pn=20,却能够直接获得内容,但用php函数获取,却怎么也不行。百度是怎么能够区别出浏览器访问和程序访问的呢?哪位达人能说说原因和指点下迷津吗。
我没更多分了,用钱买php解决方案也行啊
回复讨论(解决方案)
添加 useragent 试试,
参考:http://tuzwu.iteye.com/blog/723260
当然试过了,已经参照Fiddler2截获的数据进行了全模仿
我觉得是你网络有问题
字符集编码问题吧?
奇了怪了,用file_get_contents确实可行,但用我的方法只是百度不能获取,其他网址都成功,这是为什么呢?
字符集编码没问题,我已经反复试验过了,同样的编码,file_get_contents是可以的
不知道你是怎么写的
$fp = fsockopen("www.baidu.com", 80, $errno, $errstr, 30);$out = "GET /s?wd=音箱&pn=20 HTTP/1.1\r\n";$out .= "Host: www.baidu.com\r\n";$out .= "Connection: Close\r\n\r\n";fwrite($fp, $out);while (!feof($fp)) { echo fgets($fp, 128);}fclose($fp);这回不贴图了,贴个数据片段
resource id #2http/1.1 200 ok
date: fri, 29 nov 2013 07:21:48 gmt
server: bws/1.0
content-length: 109229
content-type: text/html;charset=utf-8
cache-control: private
bdpagetype: 3
bduserid: 0
bdqid: 0xba09dfbd018d026b
set-cookie: bdsvrtm=245; path=/
set-cookie: h_ps_pssid=4316_1462_4181_4261; path=/; domain=.baidu.com
set-cookie: baiduid=93a4febc6a24e74b727fee7001e65b50:fg=1; expires=fri, 29-nov-43 07:21:47 gmt; path=/; domain=.baidu.com
p3p: cp=" oti dsp cor iva our ind com "
connection: close
......
>音箱频道
data-click="{
|









