selenium是什么?
- seleninum模块是基于浏览器自动化的一个模块。
selenium使用流程
1)环境安装:pip install selenium
2)下载某一个浏览器的驱动程序
下载路径:https://chromedriver.storage.googleapis.com/index.html
驱动程序和浏览器的映射关系:https://blog.csdn.net/qq_38316655/article/details/112752328
3)将下载的驱动配置到系统 用户 环境变量中
-
简单的实现案例
from selenium import webdriver import time b=webdriver.Chrome() b.get("http://www.baidu.com") time.sleep(5) b.quit()
-
查找csdn中的案例
from selenium import webdriver import time bro=webdriver.Chrome() bro.get("https://www.csdn.net/") #标签定位 search_input=bro.find_element_by_id("toolbar-search-input") #标签交互 search_input.send_keys("聚焦爬虫:正则、bs4、xpath") time.sleep(1) #按钮定位 btn=bro.find_element_by_id("toolbar-search-button") btn.click() time.sleep(5) bro.quit() ```