【发布时间】:2015-12-19 20:01:01
【问题描述】:
我有一个大的查询文件,我需要在 google 中搜索并在另一个文件中返回该查询的结果 URL。我正在使用这个包 https://pypi.python.org/pypi/googlesearch/0.7.0 。
在终端中运行我的程序时,我经常会得到 20 个左右的 URL 打印到屏幕上,然后我将 GoogleSearch 切换到代理编号 1 打印到屏幕上。几分钟后,屏幕上会出现一长串以 Failed toestablish a new connection: [Errno 60] Operation timed out' 结尾的错误列表。
我的问题是为什么我首先得到结果然后代理号码切换?我怀疑我向谷歌发送了太多请求,但有时当我运行我的程序时,我可能会得到 4 个结果,然后我会收到相同的消息和错误。我能做些什么?在包中有一个文件 search.py,它确定使用哪个代理或何时更改。如果这是错误的原因,是否可以调整请求之间的时间量?
search.py的重要部分
def proxy(self):
if self.use_proxy:
return {"http": settings.PROXY_LIST[self.proxy_no]}
else:
return {"http": None}
def switch_to_next_proxy(self):
num_proxies = len(settings.PROXY_LIST)
GoogleSearch.proxy_no = (self.proxy_no + 1) % num_proxies
if self.verbose:
print >> sys.stderr, ('GoogleSearch switched to '
'proxy number %i' % self.proxy_no)
【问题讨论】:
标签: python proxy timeout google-search