Python crawler requests teaching (1): request parameters

The requests module is a network request module that can help us simulate as a client to request data from the server.

Today we are mainly studying for this module.

 

We can grab the content of these requests and responses in the browser, so can we "forge" the request? That is, instead of sending these data through the browser, we use Python to simulate the browser sending the request. The answer is feasible. The Requests module can accomplish this function.

  • The Requests module is a simple and easy-to-use HTTP library implemented by Python

Python crawler, data analysis, website development and other case tutorial videos are free to watch online

https://space.bilibili.com/523606542 

Python learning exchange group: 1039645993

Are there other libraries? The answer is also yes, such as urllib, urllib2, and other modules. But currently the Requests module is the most popular. And it is also the best module to use.

It is very convenient to install with pip:

pip install requests

requests module request parameters

Through the previous use of the requests module, we already know that the requests module can pass some keyword parameters when sending network requests, as shown in the case we wrote in the following figure:

 

So in addition to these two keyword parameters, what other keyword parameters does the requests module have when sending network requests? Next, by viewing the source code, we will introduce the commonly used keyword parameters for the requests module to send requests. As follows:

method: 请求方法 get post
url: 请求网址
params: (可选的) 查询参数

headers: (可选的) 字典 请求头
cookies: (可选的) 字典.cookiejar对象,用户身份信息
proxies: (可选的) ip代理

data: (可选的) 字典.列表.元组.bytes  post请求时会用到
json: (可选的) 字典 提交参数

verify: (可选的) 是否验证证书,ca证书
timeout: (可选的) 设置响应时间,一单超过,程序会报错
allow_redirects: (可选的) 是否允许重定向,布尔类型数据
files: (可选的) 字典,文件
auth: (可选的) 字典,权限认证
stream: (可选的) 是否是数据串流

The above keyword parameters are arranged according to the frequency of use.

Guess you like

Origin blog.csdn.net/m0_48405781/article/details/115128084