【发布时间】:2014-08-20 01:24:18
【问题描述】:
我正在使用 mechanize 在 python 中编写一个网页抓取程序。我遇到的问题是,我从中抓取的网站限制了您可以在该网站上的时间。当我手动做所有事情时,我会使用 SOCKS 代理作为解决方法。
我尝试做的是转到网络首选项(Macbook Pro Retina 13',mavericks)并更改为代理。但是,该程序没有响应这一变化。它在没有代理的情况下继续运行。
然后我添加了 .set_proxies(),所以现在打开网站的代码如下所示:
b=mechanize.Browser() #open browser
b.set_proxies({"http":"96.8.113.76:8080"}) #proxy
DBJ=b.open(URL) #open url
当我运行程序时,我得到了这个错误:
Traceback (most recent call last):
File "GM1.py", line 74, in <module>
DBJ=b.open(URL)
File "build/bdist.macosx-10.9-intel/egg/mechanize/_mechanize.py", line 203, in open
File "build/bdist.macosx-10.9-intel/egg/mechanize/_mechanize.py", line 230, in _mech_open
File "build/bdist.macosx-10.9-intel/egg/mechanize/_opener.py", line 193, in open
File "build/bdist.macosx-10.9-intel/egg/mechanize/_urllib2_fork.py", line 344, in _open
File "build/bdist.macosx-10.9-intel/egg/mechanize/_urllib2_fork.py", line 332, in _call_chain
File "build/bdist.macosx-10.9-intel/egg/mechanize/_urllib2_fork.py", line 1142, in http_open
File "build/bdist.macosx-10.9-intel/egg/mechanize/_urllib2_fork.py", line 1118, in do_open
urllib2.URLError: <urlopen error [Errno 54] Connection reset by peer>
我假设代理已更改,并且此错误是对该代理的响应。
也许我在滥用 .set_proxies()。
我不确定代理本身是问题还是连接速度真的很慢。
我什至应该使用 SOCKS 代理来处理这种类型的事情,还是有更好的替代方案来解决我正在尝试做的事情?
任何信息都会非常有帮助。提前致谢。
【问题讨论】:
标签: python proxy web-scraping mechanize