作者plom (plom)
看板Python
标题Re: [问题] 抓 google 网页的搜寻回传结果
时间Sat Dec 15 22:44:43 2007
※ 引述《plom (plom)》之铭言:
: ※ 引述《StubbornLin (Victor)》之铭言:
: : 嗯~ 经过刚才讨论一下
: : 还有我的实验
: : 发现问题出在Google疑似会挡urllib的User-Agent header
: : 以上
: 那请问有人知道如何改写吗?只有 python 不能抓, 实在太不公平了 ><
刚又试了一下
import httplib
httplib.HTTPConnection.debuglevel = 1
import urllib2
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
opener.open('
http://www.google.com.tw/search?q=time&start=20&complete=1&hl=zh-TW&sa=N&btnG=%E6%90%9C%E5%B0%8B').read()
send: 'GET
/search?q=time&start=20&complete=1&hl=zh-TW&sa=N&btnG=%E6%90%9C%E5%B0
send: 'Host: www.google.com.tw\r\n'
send: 'User-agent: Mozilla/5.0\r\n'
send: '\r\n'
reply: 'HTTP/1.0 200 OK\r\n'
接下来要下什麽指令才能抓网页呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.192.149.53