Python crawler requests teaching (3): cookies keyword parameters

When we studied the http protocol earlier, the cookies field was described in the request body field. This field represents the user's identity. Generally, the platform stores user information through this field, including but not limited to user name, password, login time, and so on.

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

Generally, cookie information is binary, that is, the form of key=value, which is very similar to the structure of a dictionary. Each key=value information represents the user's fragment information, and many key=value fragments form a complete cookie field, as shown in the following figure:

 

 

It is worth noting that all pieces of information in cookies are automatically generated by the browser, or generated by the server when responding to the data. Once the service generates cookie fragments for you, there is a high probability that these fragments will be verified to verify your user identity, and thus decide whether to return data to you. On the contrary, the cookie fragments that the browser automatically generates for us have little effect on our code requests, because the server often verifies the cookie fragments generated by itself, and does not verify the cookie fragments automatically generated by the browser.

Sending a request with cookies field in the requests module is also relatively easy to operate. To achieve this, simply pass a dictionary to the cookies keyword:

cookies ={'key1' :1value1','key2' :value2'}
response =requests . get("url",cooki es=cookies)

Guess you like

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