[python] Crawler notes (seven) simulated cookies login

http/https protocol features: stateless

Appears in: After the simulated login, the server did not record the current login status, which caused the login interface to return to the next time the request was initiated.

Cookies: used to allow the server to record the status of the client.
Insert picture description here
Solution:
1. Manual cookie acquisition, package after capturing (not recommended)
Insert picture description here
2. Automatic processing

  • The source of the cookie value is: created by the server after simulating a login post request
  • session object:
    • effect:
      • 1. Request to send
      • 2. If a cookie is generated during the request, the cookies will be automatically stored in the session object
    • Create a session object. session = requests.Session()
    • Use session object to simulate the sending of login post request
    • Use session to send the corresponding get request (carrying cookie)
    • The same format as the requests, but with cookies

Guess you like

Origin blog.csdn.net/Sgmple/article/details/112095257