InvalidArgumentException:消息:二进制文件不是Python linuxmint环境中的Firef



我测试了selenium python,在firefox中出现了这些错误,我找不到解决方案。这是我的代码

from selenium import webdriver 
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
options = Options()
options.binary = FirefoxBinary(r'/usr/bin/firefox')
driver = webdriver.Firefox(executable_path= r'./scrap/geckodriver', options=options) 
driver.get("http://www.google.com") 
print (driver.page_source.encode('utf-8') )
driver.close() 

我的错误消息python linuxmint:

selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable

我已经在论坛上搜索了几天,但我找不到linux mint的解决方案。

这是在Debian上运行selenium/Firefox设置的一个例子,它也应该在Mint上运行,因为它本质上是相同的操作系统:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options as Firefox_Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
import time as t
import pandas as pd
firefox_options = Firefox_Options()
# firefox_options.add_argument("--width=1280")
# firefox_options.add_argument("--height=720")
driverService = Service('chromedriver/geckodriver') ## path where you saved geckodriver
browser = webdriver.Firefox(service=driverService, options=firefox_options)

硒文档:https://www.selenium.dev/documentation/

作为options.binary = FirefoxBinary()的替代方案,您可以使用binary_location选项,如下所示:

options = Options()
options.binary_location = r'/usr/bin/firefox'

最新更新