Python-第七周-requests 模块的使用-03

1.概述
Python-第七周-requests 模块的使用-03_第1张图片
2.requests库的方法
Python-第七周-requests 模块的使用-03_第2张图片
(1)使用说明
Python-第七周-requests 模块的使用-03_第3张图片
3.
Python-第七周-requests 模块的使用-03_第4张图片
实例:
Python-第七周-requests 模块的使用-03_第5张图片
.
.
.
.
.

.
.
.
.
.
4.requests模块各参数的使用
(1)requests模块各参数的使用
Python-第七周-requests 模块的使用-03_第6张图片
参数1:

>>> import requests
>>> A = "https://www.baidu.com/"
>>> res = requests.get(A)  #获取网页信息
>>> res.status_code  #判断是否连接成功,200表示成功,400表示失败
200
>>> A = "https://www.zhihu.com/signin?next=%2F"  #知乎网
>>> res = requests.get(A)
>>> res.status_code
400
>>> res.text  #输出页面内容
'\r\n400 Bad Request\r\n\r\n

400 Bad Request

\r\n
openresty
\r\n\r\n\r\n'
>>> #由上面400 Bad Request可知,出现错误了。这是因为知乎有反爬虫机制。因此,我们需要用 headers 方法来获取。 >>>

Python-第七周-requests 模块的使用-03_第7张图片
参数2:
Python-第七周-requests 模块的使用-03_第8张图片
Python-第七周-requests 模块的使用-03_第9张图片
参数3:
Python-第七周-requests 模块的使用-03_第10张图片
参数4:
Python-第七周-requests 模块的使用-03_第11张图片
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5.Response对象属性
(1)
Python-第七周-requests 模块的使用-03_第12张图片
实例1:
Python-第七周-requests 模块的使用-03_第13张图片
Python-第七周-requests 模块的使用-03_第14张图片
实例2:
Python-第七周-requests 模块的使用-03_第15张图片
Python-第七周-requests 模块的使用-03_第16张图片

你可能感兴趣的:(Python学习)