selenium加载驱动的两种方式
以chrome浏览器举例
第一种
-
查看本地chrome浏览器版本:右上角-设置-关于chrome,我的版本是:120.0.6099.200
-
去对应驱动下载网站下载
-
下载好对应的网站后,将其放到与chrome安装路径一致的地方,然后将该目录添加到:系统变量-Path 中
-
然后就是去Pycharm中引入对应的包和创建函数对象
from selenium import webdriver driver = webdriver.Chrome() driver.quit()
第二种
-
# 打开pycharm,安装webdriver-manager, pip install webdriver-manager # 通过这个模块管理各类浏览器驱动,程序运行后会自动安装对应浏览器的驱动,安装目录在:%USERPROFILE%\.wdm\drivers\chromedriver from selenium import webdriver from selenium.webdriver.chrome.service import Service as ChromeService from webdriver_manager.chrome import ChromeDriverManager service = ChromeService(executable_path=ChromeDriverManager().install()) driver = webdriver.Chrome(service=service) driver.quit()
附带各类驱动下载地址
GeckoDriver(Firefox):https://github.com/mozilla/geckodriver/releases
ChromeDriver(Chrome):https://sites.google.com/a/chromium.org/chromedriver/home
IEDriverServer(IE):http://selenium-release.storage.googleapis.com/index.html
OperaDriver(Opera):https://github.com/operasoftware/operachromiumdriver/releases
MicrosoftWebDriver(Edge):https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架