#! -*- encoding:utf-8 -*-
import urllib2
handler = urllib2.ProxyHandler(proxies = {'http' : 'www.google.cn:80'})
opener = urllib2.build_opener(handler)
f = opener.open('http://www.baidu.com/')
print f.read()
需要认证:
proxy = ProxyHandler({'http','http://www.xxx.com:8080/'})
auth = HTTPBasicAuthHandler() #需要认证handler
auth.add_password('realm','host','user','pwd')
opener = build_opener(proxy,auth)