【问题标题】:Tor with Pycurl usage?Tor 与 Pycurl 的使用?
【发布时间】:2011-11-24 05:49:27
【问题描述】:

您好,我希望使用 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()

请帮忙。

【问题讨论】:

标签: python pycurl tor


【解决方案1】:

在 Ubuntu 上,我可以使用 socks5 代理使 pycurltor 上工作:

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

有类似这样的输出。请注意 tor 位于 127.0.0.1:9050 套接字

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 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-12
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多