
上QQ阅读APP看书,第一时间看更新
第6章
爬虫库Requests
6.1 Requests简介及安装
Requests是Python的一个很实用的HTTP客户端库,完全满足如今网络爬虫的需求。与Urllib对比,Requests不仅具备Urllib的全部功能;在开发使用上,语法简单易懂,完全符合Python优雅、简洁的特性;在兼容性上,完全兼容Python 2和Python 3,具有较强的适用性。
Requests可通过pip安装,具体如下。
● Windows系统:pip install requests。
● Linux系统:sudo pip install requests。
除了使用pip安装之外,还可以下载whl文件安装,方法如下:
(1)访问www.lfd.uci.edu/~gohlke/pythonlibs,按Ctrl+F组合键搜索关键字“requests”,如图6-1所示。

图6-1 安装requests
(2)单击下载requests 2.20.0 py2.py3 none any.whl,把下载文件直接解压,将解压出来的文件直接放入Python的安装目录Lib\site-packages中即可。
(3)除了解压whl,还可以使用pip安装whl文件。例如把下载的文件保存在E盘,打开CMD(终端),将路径切换到E盘,输入安装命令:

完成Requests安装后,在终端(CMD)下运行Python,查看Requests版本信息,检测是否安装成功。方法如下:
