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:
urllib2
can accept aRequest
object to set the headers for a URL request,urllib
accepts only a URL. That means, you cannot masquerade your User Agent string etc. urllib2能设置request header ,urllib不能urllib
provides theurlencode
method which is used for the generation of GET query strings,urllib2
doesn't have such a function. This is one of the reasons whyurllib
is 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相关的操作,但他们提供不同的功 ...
随机推荐
- [C/C++标准库]_[0基础]_[优先队列priority_queue的使用]
std::priority_queue 场景: 1. 对于一个任务队列,任务的优先级由任务的priority属性指明,这时候就须要优先级越高的先运行.而queue并没有排序功能,这时priority_ ...
- HDU 1002 A + B Problem II(大整数相加)
A + B Problem II Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- 杭州电子科技大学Online Judge 之 “确定比赛名次(ID1285)”解题报告
杭州电子科技大学Online Judge 之 "确定比赛名次(ID1285)"解题报告 巧若拙(欢迎转载,但请注明出处:http://blog.csdn.net/qiaoruozh ...
- paip.数据库发邮件通知配置
paip.数据库发邮件通知配置 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...
- SQL Server索引进阶:第五级,包含列
原文地址: Stairway to SQL Server Indexes: Level 5, Included Columns 本文是SQL Server索引进阶系列(Stairway to SQL ...
- 关于对象和this、new
//创建一个猫类 function Cat(name,color,eyeColor){ //上面处Cat首字母大写表示创建一个‘类别’叫Cat类.假如首字母小写cat则是创建一个cat的函数: thi ...
- API和DLL
API API(Application Programming Interface,应用编程接口)其实就是操作系统留给应用程序的一个调用接口,应用程序通过调用操作系统的 API 而使操作系统去执行应用 ...
- XML读写文件辅助类
/// <summary> /// 历史下载记录xml文件操作 /// </summary> public class XMLHelper { private string x ...
- JS 获取浏览器窗口大小clientWidth、offsetWidth、scrollWidth
常用: JS 获取浏览器窗口大小 // 获取窗口宽度 if (windows.innerWidth) winWidth = windows.innerWidth; else if ((docume ...
- vs2012-vs2013编译出来的程序不能在xp上运行解决方法
在链接标志中加入参数: /SUBSYSTEM:WINDOWS,"5.01" 在ide环境下: 项目属性-常规-平台工具集-Visual Studio 2013 - Windows ...