嗨,我想让我的爬虫用Pycurl,用Tor。我怎么能这么做?我知道如何使用httplib实现这一点。
proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
opener = urllib2.build_opener(proxy_support)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
print opener.open('http://www.google.com').read()
请帮帮忙。
发布于 2015-04-21 04:54:00
在Ubuntu上,我能够让pycurl使用socks5代理在tor上工作:
import pycurl
c = pycurl.Curl()
c.setopt(pycurl.URL, "http://whatismyipaddress.com/")
c.setopt(pycurl.PROXY, "127.0.0.1")
c.setopt(pycurl.PROXYPORT, 9050)
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5)
c.perform()
别忘了安装tor
sudo apt-get install tor
要检查tor已启动,可以运行网络监视命令:
sudo netstat -lnptu
它们有类似的输出。请注意,127.0.0.1:9050套接字上有tor。
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:49017 0.0.0.0:* LISTEN 2701/skype
tcp 0 0 127.0.0.1:9050 0.0.0.0:* LISTEN 1810/tor
tcp 0 0 0.0.0.0:17500 0.0.0.0:* LISTEN 2187/dropbox
https://stackoverflow.com/questions/8252722
复制相似问题