首页 > 解决方案 > selenium.common.exceptions.WebDriverException:消息:服务 /usr/bin/chromedriver 意外退出。状态码是:1

问题描述

我正在将 selenium 与 python 一起使用并接收此退出代码。使用 puTTY 以 root 身份运行可以正常工作,但在 apache 上运行的烧瓶文件中使用 os.system 运行不起作用。我认为这是因为它以用户 www-data[33] 的身份运行,但我已授予执行权限,但找不到它不适用于 www-data[33] 的原因。这是我的代码:

import selenium
from bs4 import BeautifulSoup, NavigableString
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from datetime import date
import sys


today = date.today()
global todaydate
todaydate = today.strftime("%m/%d/%y")
list = []

def getargs(a):
    arg = str(a)
    print(arg)
    list.append(arg)

if __name__ == "__main__":
    getargs((sys.argv[1]))

options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
options.add_argument("--headless")
options.add_argument("start-maximized")
options.add_argument("window-size=1900,1080")
options.add_argument("disable-gpu")
options.add_argument("--disable-software-rasterizer")
options.add_argument("--disable-dev-shm-usage")
options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36 Edg/92.0.902.62')
#driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=options, service_args=["--verbose", "--log-path=test.log"])
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=options)


for url in URLS:
        driver.get(url)

        innerHTML = driver.page_source
        soup = BeautifulSoup(innerHTML, "html.parser")
        
        iteminfo = []
        for i in soup.select("#ELEMENT):
            global ELEMENT
            ELEMENT= i.text
            print(ELEMENT)

标签: pythonseleniumflaskwebselenium-chromedriver

解决方案


推荐阅读