-
Prerequisite
Selenium is a third-party module and needs to be installed in advance.
pip install selenium -
Download
and put the decompressed geckodriver.exe into the path. (The installation path of python in this article has already set the PATH variable, so put it directly in the installation folder of python)
-
Open the Baidu homepage in the browser, locate the search box with the mouse, find the label of the search box, and find the id value of the tag is "kw"
- python implementation code
from selenium import webdriver
print("开始")
driver = webdriver.Firefox()
print("开始1")
url = 'http://www.baidu.com'
driver.get(url)
print("开始2")
el = driver.find_element_by_id("kw")# 通过id 来定位
print("开始3")
el.send_keys('selenium')# 向定位的搜索框传入搜索内容“selenium"
- Achieve effect