以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