urllib2使用代理服务器,urllib2代理服务器,本代码演示了python
urllib2使用代理服务器,urllib2代理服务器,本代码演示了python
本代码演示了python的urllib2模块如何使用代理,以及需要登录验证的proxy
# The proxy address and port:proxy_info = { 'host' : 'proxy.myisp.com', 'port' : 3128 }# We create a handler for the proxyproxy_support = urllib2.ProxyHandler({"http" : "http://%(host)s:%(port)d" % proxy_info})# We create an opener which uses this handler:opener = urllib2.build_opener(proxy_support)# Then we install this opener as the default opener for urllib2:urllib2.install_opener(opener)# Now we can send our HTTP request:htmlpage = urllib2.urlopen("http://sebsauvage.net/").read(200000)#如果代理需要验证proxy_info = { 'host' : 'proxy.myisp.com', 'port' : 3128, 'user' : 'John Doe', 'pass' : 'mysecret007' }proxy_support = urllib2.ProxyHandler({"http" : "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info})opener = urllib2.build_opener(proxy_support)urllib2.install_opener(opener)htmlpage = urllib2.urlopen("http://sebsauvage.net/").read(200000)
相关内容
- 批量修改图片大小Python代码,,# -*- coding
- 求一个数的最大公约数,一个数公约数,__author__ =
- 计算一个图形中的三角形数目,图形三角形数目,#!/us
- 通过 python 把家里路由的 IP 发邮件给自己,python家里
- 第三方Linux版的(网易云)音乐又想出新版了~,第三方
- python人脸识别,python人脸,OpenCV的人脸检测功
- python求txt文件中所有Z后面数字的最小值和最大值,,#
- python实现爬虫下载美女图片,,None
- common iter query,commoniter,def iquery(c
- python查看zip包中的文件及大小,python查看zip包中,#!/us
评论关闭