Home  >  Article  >  Backend Development  >  Python web crawler--about simple simulated login

Python web crawler--about simple simulated login

不言
不言Original
2018-06-02 14:18:071682browse

Today’s article mainly introduces about Python web crawler-about simple simulated login, which has certain reference value. Now I share it with everyone. Friends in need can refer to

and get the web page The information is different. If you want to simulate login, you need to send some information to the server, such as account number, password, etc.

Simulating login to a website is roughly divided into the following steps:

1. First find the hidden information of the login website and copy its contents Save first (since the website I logged in here does not have additional information, there is no information filtering and saving here)

2. Submit the information

3. Obtain the information after login

Give me the source code first

<span style="font-size: 14px;"># -*- coding: utf-8 -*-
import requests
def login():
 session = requests.session()
 # res = session.get(&#39;http://my.its.csu.edu.cn/&#39;).content
 login_data = {
 &#39;userName&#39;: &#39;3903150327&#39;,
 &#39;passWord&#39;: &#39;136510&#39;,
 &#39;enter&#39;: &#39;true&#39;
 }
 session.post(&#39;http://my.its.csu.edu.cn//&#39;, data=login_data)
 res = session.get(&#39;http://my.its.csu.edu.cn/Home/Default&#39;)
 print(res.text)
login()</span>

##1. Filter to get hidden information

Enter the developer tools (press F12), find the Network, log in manually, and find the first request. There will be a data segment at the bottom of the Header. This Just the information needed to log in. If you want to modify the hidden information

Get the Html content of the web page first

res = session.get(&#39;http://my.its.csu.edu.cn/&#39;).content

Then filter the content through regular expressions

2. Submit the information

Find the action and method required to submit the form in the source code

Use

session.post(&#39;http://my.its.csu.edu.cn/(这里就是提交的action)&#39;, data=login_data)

This method submits information

3. Obtain information after login

After the information is submitted, the simulated login is successful

Then you can get the login information

res = session.get(&#39;http://my.its.csu.edu.cn/Home/Default&#39;).content

Related recommendations:

Instance of Python crawler grabbing proxy IP and checking availability

Python crawler browser identification library

The above is the detailed content of Python web crawler--about simple simulated login. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn