使用 selenium 在无头模式下运行 Firefox 错误:“选项”对象没有属性“二进制”

Posted

技术标签:

【中文标题】使用 selenium 在无头模式下运行 Firefox 错误:“选项”对象没有属性“二进制”【英文标题】:using selenium to run Firefox in headless mode error: 'Options' object has no attribute 'binary' 【发布时间】:2021-10-14 13:11:25 【问题描述】:

我刚开始使用 selenium,想在沃尔玛检查 ps5 的状态 但我收到错误“选项”对象没有属性“二进制” 在我尝试以无头模式运行之前它运行良好。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options


options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)

driver.get('https://www.walmart.com/ip/Sony-PlayStation-5-Video-Game-Console/994712501')

print(driver.find_element_by_css_selector("div[class='prod-blitz-copy-message']").text)

【问题讨论】:

【参考方案1】:

你使用的是火狐

不是这个

from selenium.webdriver.chrome.options import Options

导入为

from selenium.webdriver.firefox.options import Options


driver = webdriver.Firefox(firefox_options=option)

【讨论】:

以上是关于使用 selenium 在无头模式下运行 Firefox 错误:“选项”对象没有属性“二进制”的主要内容,如果未能解决你的问题,请参考以下文章