2
Such a simple (unsafe) login form is rare anymore. The login form of the subtitle library is as follows, with irrelevant content omitted:
1
Through packet capture analysis, it can be found that the username and password are not encrypted:
Use POST directly to simulate login:
1 import requests 2 from bs4 import BeautifulSoup 3 4 url='' 5 data={'referer':'','username':'***','password':'***','isremember':'1'} 6 7 #创建会话 8 session=requests.session() 9 #模拟登录10 r=session.post(url,data=data)11 #解析页面12 bs=BeautifulSoup(r.text,'lxml')13 14 print(bs.body.text) #登录成功!页面自动 跳转 等待时间: 1
Successful login, analyze the js code in the returned page, and find:
href = document.getElementById('href').href; location.href = href;
Explain that the page you want to jump to is in the hyperlink with the id href:
跳转
Get the page you want to jump to, and then try to open a new page Whether the login status can be maintained:
1 href=''+bs.find(id='href').attrs['href']2 r2=ss.get(href)3 print(BeautifulSoup(r2.text,'lxml').title.text)#首页 - 用户中心 - 字幕库(zimuku.net)
The words "Home Page - User Center" are printed, and the login status is successfully maintained.
The above is the detailed content of An example tutorial on using the Request library to simulate login in Python. For more information, please follow other related articles on the PHP Chinese website!