python - 无效参数:无法终止已退出进程,使用 geckodriver 在 Python 中运行 Selenium
问题描述
操作系统:Ubuntu 18.04.3 LTS
Geckodriver 版本:0.26
Firefox 版本:76.0.1
Python 版本:3.6.9
Selenium 版本:3.141.0
我的代码:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver_options = Options()
driver_options.headless = True
browser = webdriver.Firefox(options=driver_options)
... do stuff
首先,这个设置在我的 Mac 上运行良好,当我将它发送到生产环境时,我得到了那个错误。这两天我一直在努力解决这个问题。
我发现了两个可能导致此问题的主要因素:
版本匹配。
正如这篇文章所说:
WebDriverException:消息:无效参数:无法在 RaspberryPi3 上使用 GeckoDriver、Selenium 和 Python 终止已退出进程
我检查了我的版本,它们是兼容的Geckodriver 在路径
中 我在代码旁边添加了一个软链接,因此它能够同时找到 geckodriver 和 firefoxgeckodriver和firefox都有777权限
如果我从终端以无头模式运行 Firefox,它似乎运行良好
geckodriver.log 文件正在输出:
1590245018121 mozrunner::runner INFO Running command: "/var/www/mycode/env/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile7raE8H"
/var/www/mycode/env/bin/firefox: 1: /var/www/mycode/env/bin/firefox: which: not found
解决方案
由于我可以从终端运行脚本,我最终意识到他的问题是 gunicorn。我不得不添加
Environment="PATH=/usr/bin"
到服务器上运行的 gunicorn 服务脚本。
推荐阅读
- c# - 如何按属性汇总对象列表
- html - 如何在 div 块之间缩进以使它们不背靠背?
- editor - 在 VS Code 中自定义带引号的字符串
- azure-functions - 如何通过 Azure Functions 应用在 Azure Linux VM 上执行 bash 脚本
- php - 为什么foreach输出两倍的结果
- oracle - Oracle 12.1 在 NVL 和左外连接上的性能
- python - 当时间戳高于同一组中具有值的行时,删除组中的行
- javascript - 比较对象键/值对中没有标准键的两个数组,将缺失值推送到javascript中的第一个数组
- java - 尝试仅使用嵌套的 for 循环(Java)在侧面打印带有线条的数量不断增加的金字塔
- kotlin - 使用 ktor 检查多部分请求正文中是否存在所有参数