urllib2 with proxy
import urllib2
proxy_info = {
'user' : 'username',
'pass' : 'password',
'host' : "proxy",
'port' : 80 # or 8080 or whatever
}
# build a new opener that uses a proxy requiring authorization
proxy_support = urllib2.ProxyHandler({"http" : \
"http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
# install it
urllib2.install_opener(opener)
# use it
f = urllib2.urlopen('http://www.python.org/')
print f.headers
print f.read()
TODO:
- Check how to open it in browser?
- patch to comics-grabber for proxy support. Man! I had a need for this for a long time.
No comments:
Post a Comment