python fetch with proxy

#!/usr/bin/env python
#encoding=utf-8
"""
python fetch webpage with proxy
"""
import sys
reload(sys)
sys.setdefaultencoding("utf-8")

import urllib2
proxy_support = urllib2.ProxyHandler({'http':'http://127.0.0.1:8086'}) 
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) 
urllib2.install_opener(opener) 
url="http://www.twitter.com"
url="http://www.facebook.com"
r=urllib2.urlopen(url)
html=r.read()
print html

reference:

http://developer.51cto.com/art/201003/188558.htm

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