python - 'geckodriver' 可执行文件需要通过 Selenium 使用 GeckoDriver 和 Firefox 在 PATH 中
问题描述
我非常熟悉使用 chromedriver for selenium,我现在尝试使用 geckdriver 但由于某种原因我不断收到错误'geckodriver' executable needs to be in PATH.
我按照Selenium 中的步骤使用 Python - Geckodriver 可执行文件需要在 PATH 中
我将壁虎驱动程序添加到环境变量中的路径
我将 Firefox 更新到最新版本
我使用了二进制方法
将 geckodriver 放在我的脚本所在的文件夹中
我重新启动了我的电脑
但是这些方法似乎都不起作用,我缺少什么吗?
这是我的代码
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary("C:\\Users\\ojadi\\Downloads\\geckodriver-v0.28.0-win64\\geckodriver.exe")
browser = webdriver.Firefox(firefox_binary=binary)
解决方案
您可以在系统中的任何位置下载和存储GeckoDriver可执行文件,您需要firefox
通过属性传递二进制文件的绝对路径,binary_location
如下所示:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(firefox_options=options, executable_path=r'C:\Users\\ojadi\Downloads\geckodriver-v0.28.0-win64\geckodriver.exe')
driver.get('http://google.com/')
推荐阅读
- c# - 如何从安装了图像处理设备的设备中获取视频图片?
- r - 生成内部年龄和性别 z 分数
- r - 无法打开 R 和 SQL Server 之间的连接
- flutter - 常见任务的颤振命令别名
- scala - 可由类实现但不能由对象实现的特征
- javascript - d3 行生成器返回 null 而不是路径数据字符串
- c# - 将 ServiceDescription 代码移植到 .net Core
- java - 在 spring-rest API 中从数据库中检索图像路径的理想方法是什么?
- wso2 - WSO2 基于角色的身份验证方案
- ios - 如何使用 UIPickerView 更改不同类中的标签