Python: urllib via proxy

Since I always forget, I'll note it.

import urllib
import urllib2

some_url = 'http://takamario.blogspot.com/'

# urllib
proxies = {'http': 'http://www.someproxy.com:3128'}
fh = urllib.urlopen(some_url, proxies=proxies)

# urllib2
proxy_handler = urllib2.ProxyHandler({
    'http': 'http://www.someproxy.com:3128'
    })
opener = urllib2.build_opener(proxy_handler)
fh = opener.open(some_url)

Share this

Related Posts