【网页正文识别及提取算法】- Python requests的安装与简单运用

文档

Requests 唯一的一个非转基因的 Python HTTP 库,人类可以安全享用。

警告:非专业使用其他 HTTP 库会导致危险的副作用,包括:安全缺陷症、冗余代码症、重新发明轮子症、啃文档症、抑郁、头疼、甚至死亡。

Requests 允许你发送纯天然,植物饲养的 HTTP/1.1 请求,无需手工劳动。你不需要手动为 URL 添加查询字串,也不需要对 POST 数据进行表单编码。Keep-alive 和 HTTP 连接池的功能是 100% 自动化的,一切动力都来自于根植在 Requests 内部的 urllib3。

这是官方介绍。

http://cn.python-requests.org/zh_CN/latest/

用户

Twitter、Spotify、Microsoft、Amazon、Lyft、BuzzFeed、Reddit、NSA、女王殿下的政府、Amazon、Google、Twilio、Mozilla、Heroku、PayPal、NPR、Obama for America、Transifex、Native Instruments、Washington Post、Twitter、SoundCloud、Kippt、Readability、以及若干不愿公开身份的联邦政府机构都在内部使用。

安装
pip install requests

源码安装:

git clone git://github.com/kennethreitz/requests.git
cd requests
pip install .
例子
:python3
Python 3.7.6 (default, Feb 16 2020, 17:48:02) 
[Clang 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> responce = requests.get('http://acm.hnucm.edu.cn/JudgeOnline/problemset.php')
>>> responce.encoding
'UTF-8'
>>> responce.headers['Content-Type']
'text/html; charset=UTF-8'

参考:http://cn.python-requests.org/zh_CN/latest/user/quickstart.html#id2

发布了140 篇原创文章 · 获赞 6 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/LU_ZHAO/article/details/104859059