"Ju Hui" <ph*****@gmail.com> writes:
I wanna use urllib2 to get a page with a socks 5 proxy,who can give me
a sample code ?
[...]
I haven't used it myself (though curiously, ftplib knows about this
module and will use it if present -- and urllib2 uses ftplib to fetch
ftp: URLs), but you could try this
http://www.w3.org/People/Connolly/dr...ForPython.html
And monkeypatch urllib2 (and everything else that uses module socket!)
something like so (UNTESTED):
import sys, os
os.environ['SOCKS_SERVER'] = 'joe:pa******@proxy.example.org'
import SOCKS
from socket import getfqdn
SOCKS.getfqdn = getfqdn
sys.modules['socket'] = SOCKS
del getfqdn, SOCKS
import urllib2
then just use urllib2 normally...
John