Selenium4.0实现自动搜索功能
01.Selenium4.0实现搜索功能
1.安装Selenium及查看Selenium版本
pip install selenium
pip show selenium
from selenium import webdriver
from chromedriver_py import binary_path
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
#启动Chrome
svc = webdriver.ChromeService(executable_path=binary_path)
driver = webdriver.Chrome(service=svc)
#打开baidu网址
driver.get('http://www.baidu.com')
# 设置窗口大小
#driver.set_window_size(1920, 1080)
time.sleep(5)
a = driver.find_element(By.ID, "kw")
#输入搜索字符
a.send_keys("python")
a.send_keys(Keys.RETURN)
time.sleep(20)
driver.quit()