I wanna use urllib2 to get a page with a socks 5 proxy, who can give me a sample code ?
John J. Lee
jjl at pobox.com
Tue Apr 11 19:52:47 EDT 2006
"Ju Hui" <phpbird at 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/drafts/socksForPython.html
And monkeypatch urllib2 (and everything else that uses module socket!)
something like so (UNTESTED):
import sys, os
os.environ['SOCKS_SERVER'] = 'joe:password at 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
More information about the Python-list
mailing list