# coding=utf-8
# urllib_get_file=urllib.request.urlretrieve(url=None,filename="test.zip")
# basic usage of urllib
from urllib import request
url = "https://www.cnblogs.com/SunshineKimi/"
msg = request.Request(url)
# msg.add_header("1",2)
# msg.set_proxy()
rep = request.urlopen(msg)
print(rep.read()) # how to use proxy to request in urllib
proxies = {"http": "user:passwd@ip:port"} # buy proxy
proxy = {"http": "111.79.44.217:9999"} # free proxy
proxy_handler = request.ProxyHandler(proxy) # there also exist HttpHandler() basic handler
opener = request.build_opener(proxy_handler)
response = opener.open(url, data=None)
print(response.headers) # auth by proxy
passwd_manager=request.HTTPPasswordMgrWithDefaultRealm()
passwd_manager.add_password(realm=None,uri=proxy,user="user",passwd="password")
buy_auth_handler=request.ProxyBasicAuthHandler(passwd_manager)
opener_auth=request.build_opener(buy_auth_handler)
response_auth=opener_auth.open(url=None,data=None).read()
print(response_auth)

  

最新文章

  1. .Net程序员之Python基础教程学习----判断条件与循环[Fourth Day]
  2. UITableView和UICollectionView的方法学习一
  3. Android 2.3 不支持印度文
  4. [转载]HTML5 Audio/Video 标签,属性,方法,事件汇总
  5. HTML几类标签的应用总结
  6. [Thinkbayes]贝叶斯思维读书笔记-2-火车头问题
  7. print打印网页相关
  8. perl的正则表达式
  9. deeplearning.ai 改善深层神经网络 week3 超参数调试、Batch正则化和程序框架 听课笔记
  10. Python之路【第一篇】:Python简介和入门
  11. I/O模型系列之三:IO通信模型BIO NIO AIO
  12. SVN忽略已提交的文件(ignore,移出版本控制)
  13. 《了不起的 nodejs》中 TwitterWeb 案例 bug 解决
  14. CF1109D Sasha and Interesting Fact from Graph Theory
  15. .NET Core微服务之路:基于Consul最少集群实现服务的注册与发现(二)
  16. HDU 4391 Paint The Wall(分块的区间维护)
  17. (转发)一个通用的C++ 消息总线框架
  18. 深度学习基础系列(七)| Batch Normalization
  19. go练习4--json 序列号反序列化
  20. ajax 测试

热门文章

  1. 小白的linux笔记1:CentOS 8 安装与设置
  2. warning Unexpected use of undefined no-undefined
  3. tensorflow安装问题
  4. linux下安装lxml包
  5. ajax 携带参数传递 页面 查找
  6. Java多线程之互斥锁Syncharnized
  7. Android实战项目——家庭记账本(一)
  8. Mybaits(10)N+1问题
  9. Window Api 通过账号密码访问共享文件夹
  10. 使用 VMware Workstation Pro 安装新的虚拟机