pip install PySocks
单链接代理
import socks
s = socks.socksocket()
s.set_proxy(socks.SOCKS5, "localhost", 8888)
s.connect(("www.somesite.com", 80))
s.sendall("GET / HTTP/1.1 ...")
print s.recv(4096)
项目无侵入代理
import socket
import socks
import urllib.request
socks.setdefaultproxy(socks.SOCKS5, "localhost", 10808)
socket.socket = socks.socksocket
data = urllib.request.urlopen("http://www.youtube.com").read()
print(data)
import socket
import socks
def enable(host="localhost", port=10808):
socks.setdefaultproxy(socks.SOCKS5, host, port)
socket.socket = socks.socksocket