The text and pictures in this article come from the network, only for learning, communication, do not have any commercial purposes, if you have any questions, please contact us to deal with.
The following article is from tomato fried tomato, by: Tomato fried tomato 715
The first thing you need is a Chrome browser
Then download chromedriver for Google chrome
Download address:
http://chromedriver.storage.googleapis.com/index.html
Copy the code
The relevant version can be seen in the first folder in the Google root directory
Download the corresponding ChromeDriver
Put it in the installation root directory
Then we enter the Python phase
First, you need to download the Selenium package
Directly in the Anaconda Prompt
pip install selenium
Copy the code
Then in Python, import the module first
from selenium import webdriver
import os
import time
Copy the code
Locate chromedriver
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
Copy the code
Simulate opening a browser
driver = webdriver.Chrome(chromedriver)
driver.get("https://bbs.hcbbs.com/")
driver.maximize_window()
Copy the code
Then start simulating the keys
Take haichuan Forum as an example
We log in with a user name and password
First click on F12
Exhale a lot of unreadable stuff
Then right click on the login location
Click “Check”
The code on the right locates the corresponding control command
Look at this line of code
Right click – copy – copyXpath
The corresponding control position is obtained
Find the control and click
driver.find_element_by_xpath('//*[@id="lsform"]/div/div[1]/p[1]/a').click()
Copy the code
The login page is displayed
Use the same method to find the control code for the username and password entry fields
Find the control and enter
driver.find_element_by_xpath('//*[@id="username"]').send_keys(myuername1)
driver.find_element_by_xpath('//*[@id="password"]').send_keys(mypassword1)
Copy the code
Click log in and click sign in
Driver. Find_element_by_xpath (' / / * [@ id = "abtn"] '). Click () # login time. Sleep (1) Driver. Find_element_by_xpath (' / / * [@ id = "fx_checkin_b"] '). Click (#) sign inCopy the code
The complete code is as follows
from selenium import webdriver
import os
import time
myuername1='********'
mypassword1='**********'
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("https://bbs.hcbbs.com/")
driver.maximize_window()
time.sleep(2)
print('111')
driver.find_element_by_xpath('//*[@id="lsform"]/div/div[1]/p[1]/a').click()
driver.find_element_by_xpath('//*[@id="username"]').send_keys(myuername1)
driver.find_element_by_xpath('//*[@id="password"]').send_keys(mypassword1)
driver.find_element_by_xpath('//*[@id="abtn"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="fx_checkin_b"]').click()
Copy the code
Is it convenient?
Set up all the sites you need to check in to
A little bit every morning
Then make a cup of tea
I signed in ~