python use proxy fetch webpage

#!/usr/bin/env python
#encoding=utf-8
import urllib2
proxy_handler=urllib2.ProxyHandler({'http' : 'http://127.0.0.1:8086'})
opener = urllib2.build_opener(proxy_handler)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib2.install_opener(opener)
url="http://www.baidu.com"
req=urllib2.Request(url)
html=urllib2.urlopen(req).read()
print html

原文地址:https://www.cnblogs.com/lexus/p/2479975.html