Python|Automatically realize learning through login

Foreword

Recently, the editor is learning python to automate the processing of web pages, because I have been using Xuetong, so I wrote a simple program for python to automate the webpage login to learntong, because I just started, I hope readers can put forward the shortcomings.

Operating environment configuration

Install selenium module

We can install it by typing pipinstall selenium in python.

Install Chrome webdriver

When installing Chrome webdriver, we need to pay attention to the version correspondence, here is the version of the corresponding Google browser; my Google browser version is 85.0.4183.102, and the webdriver version I installed is 85.0.4183.87, so that it will not run Will report an error.

Installation URL:

http://chromedriver.storage.googleapis.com/index.html。

Program running code

When our operating environment is configured, we can write the code.

from selenium import webdriver class Webdriver: def main(self): user = input('Please enter the learning pass account:') password = input('Please enter the learning pass password:') global wb # Declare global variables to prevent Chrome from running Wb = webdriver.Chrome(r'E:\weixin_dis\chromedriver.exe') wb.implicitly_wait(10) # Set the maximum time for positioning wb.get('https://passport2.chaoxing.com/login ?fid=&newversion=true&refer=http%3A%2F%2Fi.chaoxing.com') wb.find_element_by_id('phone').send_keys(user) # Locate the input account wb.find_element_by_id('pwd').send_keys(password) # Locate and enter the password wb.find_element_by_id('loginBtn').click() # Locate and click to log in if name =='main': s = Webdriver() s.main()

When we start the program and enter the account number and password, we can directly log in to the personal space of Chaoxing Xuetong; is it very convenient!

to sum up

The experience is that the selenium module uses programs to imitate human manipulation of web pages, such as input, mouse clicks, and other operations. If combined with data mining such as crawlers, it will play a very good role; in the follow-up study, I will Try to write a program that learns to sign in automatically, I hope this article is helpful to readers.

END

Intern Editor | Wang Wenxing

Responsible Editor | WZY

**The stronger the ability, the greater the responsibility. Seek truth from facts, rigorous and meticulous. **

** ——Where2go team**

Recommended Posts

Python|Automatically realize learning through login