Installation selenium
#Python
pip install selenium
#Anaconda3
conda install selenium
Download the browser version corresponding driver files
chrome
chrome driverfirefox
firefox driver
Unzip the downloaded file to the Python interpreter at the corresponding directory
Common Operations
from selenium import webdriver
import time
url = "https://www.qy1.xyz/auth/login"
browser = webdriver.Chrome()
browser.get(url)
# 点击网页的登陆按钮
# time.sleep(3)
# browser.find_element_by_xpath('/html/body/div[1]/div[3]/div[6]/div/div[3]/p[2]').click()
account = 'xxxx'
password = 'xxxx'
# try:
browser.find_element_by_xpath("//input[@name=\"email\"]").send_keys(account)
browser.find_element_by_xpath("//input[@name=\"password\"]").send_keys(password)
browser.find_element_by_xpath("//button[@type=\"submit\"]").click()
# browser.find_element_by_id("email").send_keys(account)
# browser.find_element_by_id("password").send_keys(password)
# browser.find_element_by_xpath('/html/body/div[1]/section/div/div/div/div[2]/form/div/div[5]/button').click()
# except:
# browser.find_element_by_id("email").send_keys(account)
# browser.find_element_by_id("password").send_keys(password)
# browser.find_element_by_xpath ('/html/body/div[1]/section/div/div/div/div[2]/form/div/div[5]/button/font/font').click()
time.sleep(5)
browser.find_element_by_xpath("//button[contains(text(), '已读')]").click()
# browser.find_element_by_xpath("//button[@type=\"button\"], '已读')]").click()
# browser.find_element_by_xpath('/html/body/div[2]/div/div/div[3]/button').click()
browser.find_element_by_xpath('/html/body/div[1]/div/div[2]/aside/ul/li[8]/a').click()
# 滚屏到指定的位置
browser.execute_script('window.scrollTo(0,2000)')
# 截屏
browser.save_screenshot('some.png')
# 关闭浏览器(不一定能关掉)
browser.close()