首页 > 解决方案 > 如何在带有 Firefox 的 CentOS 6.10 中使用 Python 运行 selenium webdriver

问题描述

我正在尝试在 CentOS 服务器中运行 Python 脚本。但是,我一直无法安装 Google Chrome(我已经读过它不再受 CentOS 支持),所以我决定尝试使用 Firefox。但是,尝试使用 Firefox 运行它时出现以下错误。

Traceback (most recent call last):
File "/home/uscomplianceserv/public_html/scrapdata/FMCSAScraper.py", line 73, in <module>
init_selenium()
File "/home/uscomplianceserv/public_html/scrapdata/FMCSAScraper.py", line 40, in init_selenium
webdriver.Firefox(firefox_options = options, executable_path='/home/uscomplianceserv/public_html/scrapdata/geckodriver')
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 133, in __init__
if options.binary is not None:
AttributeError: 'Options' object has no attribute 'binary'

这就是我正在使用的:

这是 selenium webdriver 初始化函数:

def init_selenium():
    global driver, page
    options = Options()
    options.add_argument("-headless")
    driver = webdriver.Firefox(firefox_options = options, executable_path='/home/uscomplianceserv/public_html/scrapdata/geckodriver')
    driver.get(url)

标签: pythonseleniumselenium-webdrivercentosgeckodriver

解决方案


推荐阅读