首页 > 解决方案 > 无效参数:无法终止已退出进程,使用 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 上运行良好,当我将它发送到生产环境时,我得到了那个错误。这两天我一直在努力解决这个问题。

我发现了两个可能导致此问题的主要因素:

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

标签: pythonseleniumubuntugunicorngeckodriver

解决方案


由于我可以从终端运行脚本,我最终意识到他的问题是 gunicorn。我不得不添加 Environment="PATH=/usr/bin" 到服务器上运行的 gunicorn 服务脚本。


推荐阅读