Simulate logon using the Request library in Python (1): The font library (no encryption, no verification code), pythonrequest
Such simple (Insecure) login forms are rare. The following figure shows the log-on Form of the font library, saving irrelevant content:
1 <form class = "login-form" action = "/User/login.html" method = "post"> 2 <input type = "hidden" name = "referer" value =" http://www.zimuku.net/"> 3 <input type =" text "id =" inputEmail "datatype =" * 1-16 "value =" "name =" username "> 4 <input type = "password" id = "inputPassword" datatype = "* 6-20" name = "password"> 5 <input type = "checkbox" name = "isremember" value = "1" checked = ""> 6 <button type = "submit" class = "btn submit-btn"> login </button> 7 </form>
Through packet capture analysis, we can find that the user name and password are not encrypted:
Directly use POST to simulate Logon:
1 import requests 2 from bs4 import BeautifulSoup 3 4 url = 'HTTP: // www.zimuku.net/User/login.html' 5 data = {'Referer': '', 'username ':'***', 'Password': '***', 'ismember': '1'} 6 7 # create session 8 session = requests. session () 9 # simulate logon 10 r = session. post (url, data = data) 11 # resolution page 12 bs = BeautifulSoup (r. text, 'lxml') 13 14 print (bs. body. text) # login successful! Automatic page Jump wait time: 1
Log on successfully. Analyze the js Code on the returned page and find the following:
href = document.getElementById('href').href;location.href = href;
The page to jump to is displayed in the href hyperlink:
<A id = "href" href = "/User/index.html"> redirect </a>
Obtain the page to jump to, and then try to open the new page, whether the logon status can be maintained:
1 href = 'HTTP: // www.zimuku.net '+ bs. find (id = 'href '). attrs ['href '] 2 r2 = ss. get (href) 3 print (BeautifulSoup (r2.text, 'lxml '). title. text) # Home Page-user center-text Library (zimuku.net)
The "homepage-user center" is printed, and the logon status is successfully maintained.