Simulate logon using the Request library in Python (1): The font library (no encryption, no verification code), pythonrequest

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.