gpt4 book ai didi

python - ubuntu: 'geckodriver' 可执行文件需要在 PATH 中

转载 作者:行者123 更新时间:2023-12-04 18:58:43 26 4
gpt4 key购买 nike

我在同一目录中安装了 firefox 和 geckodriver.exe。相同的代码在 Windows 中有效,但是当我尝试在 ubuntu 中使用它时,出现以下错误:'geckodriver.exe' executable needs to be in PATH.代码如下:

import time
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

url = 'https://www.idealista.com/venta-viviendas/barcelona/eixample/la-dreta-de-l-eixample/?ordenado-por=fecha-publicacion-desc'
options = Options()
options.headless = False
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver')
driver.get(url)
time.sleep(10)
我尝试使用相同的代码而不用 r 调用壁虎:驱动程序 = webdriver.Firefox(options=options, executable_path='geckodriver')

最佳答案

您可以使用 webdriverManager,它是最新的,不需要二进制驱动程序扩展。因此它永远不会显示您得到的错误:geckodriver.exe' executable needs to be in PATH.您必须安装 selenium4pip install webdriver-manager

#selenium4
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.options import Options

driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()),options=options)


url = 'https://www.idealista.com/venta-viviendas/barcelona/eixample/la-dreta-de-l-eixample/?ordenado-por=fecha-publicacion-desc'
options = Options()
options.headless = False
driver.get(url)
time.sleep(10)
webdriverManager

关于python - ubuntu: 'geckodriver' 可执行文件需要在 PATH 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72403723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com