首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >InvalidArgumentException:消息:在Python环境中二进制不是火狐可执行错误

InvalidArgumentException:消息:在Python环境中二进制不是火狐可执行错误
EN

Stack Overflow用户
提问于 2022-08-29 14:37:44
回答 2查看 324关注 0票数 0

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

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable

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

EN

回答 2

Stack Overflow用户

发布于 2022-08-29 15:18:54

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

代码语言:javascript
运行
复制
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/

票数 0
EN

Stack Overflow用户

发布于 2022-08-29 21:47:42

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

代码语言:javascript
运行
复制
options = Options()
options.binary_location = r'/usr/bin/firefox'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73530481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档