如何在 urllib2 中使用 SOCKS 4/5 代理? [英] How can I use a SOCKS 4/5 proxy with urllib2?

查看:75
本文介绍了如何在 urllib2 中使用 SOCKS 4/5 代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用带有 urllib2 的 SOCKS 4/5 代理下载网页?

How can I use a SOCKS 4/5 proxy with urllib2 to download a web page?

推荐答案

您可以使用 SocksiPy 模块.只需将文件socks.py"复制到 Python 的 lib/site-packages 目录,就可以开始了.

You can use SocksiPy module. Simply copy the file "socks.py" to your Python's lib/site-packages directory, and you're ready to go.

您必须在 urllib2 之前使用 socks.(试试pip install PySocks )

You must use socks before urllib2. (Try it pip install PySocks )

例如:

import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 8080)
socket.socket = socks.socksocket
import urllib2
print urllib2.urlopen('http://www.google.com').read()

您也可以尝试 pycurl lib 和 tsocks,了解更多详情,请点击此处.

You can also try pycurl lib and tsocks, for more detail, click on here.

这篇关于如何在 urllib2 中使用 SOCKS 4/5 代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆