python - 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)
解决方案
推荐阅读
- database - 保存休眠对象而不获取外键实体,仅按 id 保存
- flutter - 关于在 Cloud Firestore 中查询
- java - 小米不连接ws,其他手机是的
- java - 登录页面 未找到。未找到 Jsp 页面。从 jboss 7.1.1 迁移到 Wildfly 13
- android - 在recyclerview项目android中更改视图之间的焦点
- javascript - Javascript forEach 循环不会继续下一次迭代
- android - android上的html页面中的链接不起作用
- events - Bootstrap Datepicker:单击活动日期事件
- python - 使用 django 在新窗口中显示数据库文件
- python - 用 BeautifulSoup 隔离脚本