python urllib和urllib2 区别
python有一个基础的库叫httplib。httplib实现了HTTP和HTTPS的客户端协议,一般不直接使用,在python更高层的封装模块中(urllib,urllib2)使用了它的http实现。
一直以为urllib2是urllib2的升级版,其实不是。
一篇老外写的文章:
What is the difference between urllib and urllib2 modules of Python?
You might be intrigued 好奇的by the existence of two separate URL modules in Python - urllib andurllib2. Even more intriguing: they are not alternatives for each other. So what is the difference between urllib and urllib2, and do we need them both?
urllib and urllib2 are both Python modules that do URL request related stuff but offer different functionalities. Their two most significant differences are listed below:
urllib2can accept aRequestobject to set the headers for a URL request,urllibaccepts only a URL. That means, you cannot masquerade your User Agent string etc. urllib2能设置request header ,urllib不能urllibprovides theurlencodemethod which is used for the generation of GET query strings,urllib2doesn't have such a function. This is one of the reasons whyurllibis often used along withurllib2.
urllib提供urlencode功能。
For other differences between urllib and urllib2 refer to their documentations, the links are given in the References section.
Tip: if you are planning to do HTTP stuff only, check out httplib2, it is much better than httplib or urllib or urllib2.
Exercise
- What is User Agent?
- What is the difference between GET and POST request methods?
- What is HTTP?
References
python urllib和urllib2 区别的更多相关文章
- Python:urllib和urllib2的区别(转)
原文链接:http://www.cnblogs.com/yuxc/ 作为一个Python菜鸟,之前一直懵懂于urllib和urllib2,以为2是1的升级版.今天看到老外写的一篇<Python: ...
- Python:urllib和urllib2的区别
urllib和urllib2都是处理url请求的两个模块,但是相互之间存在不同,不能相互取代 urllib2可以接受一个Reuqest类的实例来设置URL请求的headers,urllib仅可以接受U ...
- Python urllib和urllib2模块学习(二)
一.urllib其它函数 前面介绍了 urllib 模块,以及它常用的 urlopen() 和 urlretrieve()函数的使用介绍.当然 urllib 还有一些其它很有用的辅助方法,比如对 ur ...
- Python urllib和urllib2模块学习(一)
(参考资料:现代魔法学院 http://www.nowamagic.net/academy/detail/1302803) Python标准库中有许多实用的工具类,但是在具体使用时,标准库文档上对使用 ...
- python urllib 和 urllib2
urllib 和 urllib2 都是接受URL请求的相关模块,但是提供了不同的功能.两个最显著的不同如下: urllib 仅可以接受URL,不能创建 设置了headers 的Request 类实例: ...
- Python urllib和urllib2模块学习(三)
build_opener()详解: 1.urllib2.urlopen()函数不支持验证.cookie或者其它HTTP高级功能,要支持这些功能,必须使用build_opener()函数创建自定这句话的 ...
- urllib与urllib2的学习总结(python2.7.X): python urllib与urllib2
https://www.cnblogs.com/wly923/archive/2013/05/07/3057122.html
- 爬虫新手学习2-爬虫进阶(urllib和urllib2 的区别、url转码、爬虫GET提交实例、批量爬取贴吧数据、fidder软件安装、有道翻译POST实例、豆瓣ajax数据获取)
1.urllib和urllib2区别实例 urllib和urllib2都是接受URL请求相关模块,但是提供了不同的功能,两个最显著的不同如下: urllib可以接受URL,不能创建设置headers的 ...
- 理解urllib、urllib2及requests区别及运用
urllib and urllib2 区别 –博主提示:下面的是python2中的用法,python3需要做出相应修改. urllib和urllib2模块都做与请求URL相关的操作,但他们提供不同的功 ...
随机推荐
- Duanxx的图像处理学习: 透视变换(一)
当人用眼睛看事物的时候,会感觉到近处的东西是比远处的东西要大一些的,通俗的说,这就是透视. 总的来说.透视变换是将3D的世界转换到2D图像上的一种手段,人的视觉系统和摄像头视觉系统也是基于这一工作原理 ...
- 23种设计模式的C++实现
之前看Head First设计模式的时候照着书上的代码实现了一个C++版本(书上是Java版本的),代码上传在https://github.com/clpsz/Book-HFDP-Code. 当时因为 ...
- os基础
命令:指计算机用户要求计算机系统为其工作的指示: 命令的表示形式: 1.字符形式: 2.菜单形式: 3.图形形式: 命令的使用方式:1. 脱机使用方式 off_line 2.联机使用方式 ...
- Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (四) —— ContentProvider
ContentProvider是安卓平台中,在不同应用程序之间实现数据共享的一种机制.一个应用程序如果需要让别的程序可以操作自己的数据,即可采用这种机制.并且此种方式忽略了底层的数据存储实现,Cont ...
- new Date()的参数
前两天发现手机页面的倒计时在Android上正常显示,在iPhone却不能显示. 后来又发现在ff和ie里也不显示.(以前只在chrome里看过,显示正常). 后来同事改了new Date()里字符串 ...
- viewport的作用
<meta name="viewport" content="width=device-width,height=device-height,inital-scal ...
- nodejs入门demo
demo的实例引用自:http://www.runoob.com/nodejs/nodejs-event.html, 官方文档:https://nodejs.org/dist/latest-v6.x/ ...
- CentOS修改IP
编辑 /etc/sysconfig/network-scripts/ifcfg-eth0 然后 service network restart DEVICE=eth0BOOTPROTO=noneNM_ ...
- LintCode-比较字符串
题目描述: 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是 大写字母 注意事项 在 A 中出现的 B 字符串里的字符不需要连续或者有序. 样例 给出 A = " ...
- Java解析器
http://www.infoq.com/cn/articles/HIgh-Performance-Parsers-in-Java-V2?utm_source=infoq&utm_medium ...