Some time ago wrote a complete login via cookies, and today we write request is sent by post to complete the sign Douban
Login simulation
1, first find the login watercress network interfaces
Open watercress web login interface to request the account password wrong, find the login interface via the F12 or packet capture tool
Interface login request to get F12 by Ethereal
2, analysis logon interface parameter data
The above has crawled into the login interface, the following analysis by F12 or capture tool interfaces which request parameter
View form Data This place has the wrong name and the wrong password account we have just entered, and that this is what we need the interface parameters
3, post request by sending requests
The above all we need have been found, the following code began knocking ~~
Return data can be seen by observing the already successful login.
4, receives the return value to see if the login is successful
We do interface testing in time to see his usually returns the contents to see if the login is successful
# Determine whether the login is successful IF ' success ' in r.text: Print ( ' Login successful ' ) the else : Print ( ' Login failed ' )
Complete code:
# coding:utf-8 import requests # 登录请求地址 url = 'https://accounts.douban.com/j/mobile/login/basic' # 请求头 headers = { "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36" } # body数据 data = { 'name':"XXXXX", # 账号 "password":"XXXX", # 密码 "remember":"false" } # 发送请求 r = requests.post(url,headers=headers,data=data) # 判断是否登录成功 if '成功' in r.text: print('登录成功') else: print('登录失败')
感觉写的对您有帮助的话,点击关注,持续更新中~~~~