Python web crawler - Log on simple simulation examples to explain

Xiao Bian today to share a Python web crawler for everyone - Log on simple simulation examples to explain, a good reference value, we want to help. Xiao Bian together to follow up to see it
and get different information on the page, you want to simulate the login need to send some information to the server, such as account numbers, passwords and so on.

Login simulation steps so roughly divided into a website:

1. First hidden information visit the website to find, and content to save (because the site I log on here and no additional information, so there is no filter the information stored)

2. The information submitted

3. Get information after login

Give the source code

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

First, screened hide information

After entering the Developer Tools (press F12), locate one of the Network, to conduct a manual login, find the first request of them, there will be a data segment data in the bottom of the Header, the login information is required. If you want to hide information which is to be modified

先获取网页Html的内容	
res = session.get('http://my.its.csu.edu.cn/').content

Through the regular expression filter content Here Insert Picture Description
Here Insert Picture Description
, the information submitted two

Action to find the source code needed to submit a form, and method

use

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

The method to submit information

Third, access to information after login

After the information submitted on the success of simulation login

Then you can get a login information

res = session.get('http://my.its.csu.edu.cn/Home/Default').content

I write to you, for everyone to recommend a very wide python learning resource gathering, click to enter , there is a senior programmer before learning to share experiences, study notes, there is a chance of business experience, and for everyone to carefully organize a python zero the basis of the actual project data, daily python to you on the latest technology, prospects, learning to leave a message of small details
than this Python web crawler - Log on simple simulation examples to explain Xiao Bian is to share the entire contents of all of the

Published 38 original articles · won praise 26 · views 40000 +

Guess you like

Origin blog.csdn.net/haoxun09/article/details/104741632