python urllib2 代理访问 google 报错[Errno 10060]

2016-01-03 22:53:39 +08:00
 ninestep

我想要抓取 google 搜索结果,设置全局代理可以抓取,但是在 urllib 中就会报错[Errno 10060]
代理绝对可用,谁遇到过这种事情
我的代码

name=urllib.quote(wd)
proxy ='127.0.0.1:8787'
opener = urllib2.build_opener( urllib2.ProxyHandler({'socks':proxy}) )
urllib2.install_opener( opener )
url='https://www.google.co.jp/search?hl=en&q=intitle:%s+site:%s'%(name,url)
# url='http://www.baidu.com/s?wd=intitle:%s+site:%s'%(name,url)
request=urllib2.Request(url)
user_agents = ['Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20130406 Firefox/23.0', \
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0', \
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533+ \
(KHTML, like Gecko) Element Browser 5.0', \
'IBM WebExplorer /v0.94', 'Galaxy/1.0 [en] (Mac OS X 10.5.6; U; en)', \
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)', \
'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14', \
'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) \
Version/6.0 Mobile/10A5355d Safari/8536.25', \
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) \
Chrome/28.0.1468.0 Safari/537.36', \
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0; TheWorld)']
index = random.randint(0, 9)
user_agent = user_agents[index]
request.add_header('User-Agent',user_agent)
try:
html=urllib2.urlopen(request,timeout=120)
except urllib2.URLError, e:
print(e)
return False
else:
text=html.read()

21671 次点击
所在节点    Python
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/248055

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX