4

关于不得不在python中使用代理访问网络的方法

 1 year ago
source link: https://blogread.cn/it/article/1967?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

关于不得不在python中使用代理访问网络的方法

浏览:3351次  出处信息

公司最近的网络限制越来越严格了,除了公司自己业务的任何网站,软件,都必须通过代理访问。
于是我华丽的发现google code更新不了代码了,等了两天,实在受不了找企业IT部,发现svn是可以配置代理的,如图:

1

试了一下svn up,可以用啦,不错不错,大快~,结果再试了一下svn ci,于是又杯具了……

唉,估计是代理对https的协议支持不好,罢了罢了,翻过一墙还是一墙,那我就只更新吧。

但是事情并没有结束,我有时候需要写程序去抓取外网的网页数据:

import urllib
url = 'http://www.vimer.cn'
data = urllib.urlopen(url).read()

简洁的python,但是用不了……

换urllib2,加代理:

import urllib,urllib2
url   = 'http://www.vimer.cn/'
proxy = 'xxx.xxxx.com:8080'
opener = urllib2.build_opener( urllib2.ProxyHandler({'http':proxy}) )
urllib2.install_opener( opener )
sContent = urllib2.urlopen(url)
print sContent.read()

这样总算是OK了,真是不明白,为啥上个网就得这么难呢?

PS:就在我发这篇文章的时候,我发现windows live writer也需要配置代理,唉……

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK