开发者

Removing SOCKS 4/5 proxy

开发者 https://www.devze.com 2023-01-15 03:41 出处:网络
This question is sort of the opposite of this: How can I use a SOCKS 4/5 proxy with urllib2? Let\'s say I use a SOCKS 5 proxy using the method accepted in that question. How would I revert it back

This question is sort of the opposite of this:

How can I use a SOCKS 4/5 proxy with urllib2?

Let's say I use a SOCKS 5 proxy using the method accepted in that question. How would I revert it back to 开发者_Python百科no proxy in the same process?

i.e start process use proxy .. remove proxy ...

Maybe there is a better way to use the proxy so that it's easier to remove it later?


Abra kadabra

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

精彩评论

暂无评论...
验证码 换一张
取 消