One 、 Introduce
Selenium Is an automated testing tool for testing websites , Support for a variety of browsers including Chrome、Firefox、Safari And so on the mainstream interface browser , It also supports phantomJS Interface free browser
official API file :http://seleniumhq.github.io/selenium/docs/api/py/api.html
Two 、 Environmental installation
1、 Installation Library
2、 download chromedriver : Sign in http://chromedriver.storage.googleapis.com/index.html download ( Please check the version corresponding to the browser Online )
View corresponding version , Take Google browser for example
Open the browser , Press F12, Click on console
navigator.appCodeName
navigator.appVersion
navigator.userAgent
Press F12, Click on console, Enter the following command , Can be seen as 102.0.5005.115 edition
After downloading chromedriver.exe File to python.exe In the directory Such as : D:\Program Files\Python
thus , Environment installation complete
3、 ... and 、 Write code
Search box positioning
Baidu search button positioning
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time
import os
from selenium import webdriver
# Instantiate the browser
driver = webdriver.Chrome()
# Open the url
driver.get('https://www.baidu.com/')
# demand
driver.find_element(By.ID,"kw").send_keys(' Pot pot ')
driver.find_element(By.ID, "su").click()# Click button
sleep(2)
# Close page
driver.quit()