urllib2设置代理

#coding=utf-8
#公司网络只有连接vpn跳板机才能使用该模块
import urllib2
proxy_handler=urllib2.ProxyHandler({'http':'http://username:password@proxyhk.huawei.com:8080', 'https':'https:// username:password @proxyhk.huawei.com:8080'})
opener=urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
req=urllib2.Request('http://www.baidu.com/')
conn=urllib2.urlopen(req)
print conn.read()

 

posted @ 2017-01-21 15:41  知行Lee  阅读(3585)  评论(0编辑  收藏  举报