python - 铬浏览器意外退出(Ubuntu 服务器)
问题描述
我似乎无法让 Chromedriver 与 Ubuntu 一起使用。我在 AWS (EC2) 上运行 Ubuntu。我查了一下/usr/bin
,发现里面有以下包:
chromedriver
chromium-browser
所以,我的代码如下:
options = Options()
options.binary_location = '/usr/bin/chromium-browser'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome(executable_path='/usr/bin/chromium-browser', chrome_options=options)
而且,我收到以下错误:
Traceback (most recent call last):
File "test.py", line 40, in <module>
driver = webdriver.Chrome(executable_path='/usr/bin/chromium-browser', chrome_options=options)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/chromium-browser unexpectedly exited. Status code was: 1
如果我检查我当前的 Chrome 浏览器版本,我发现我使用的是 78.0.3904.70 版本。我使用的驱动程序是否可能已过期?
我也想知道:chromium-browser 和 Chromedriver 有什么区别?我过去曾使用 Chromedriver 登录 Chrome 以与 Selenium 一起使用。
解决方案
您需要将可执行路径设置为,chromedriver
因为这是selenium
使用的。所以那行代码需要是:
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', chrome_options=options)
推荐阅读
- node.js - 如何使用 KeyConditionExpression 查询 AWS DynamoDb?
- ruby-on-rails - Elasticsearch 6.3.2 术语匹配空数组“加”其他
- python-3.x - 使用 firebase_admin python 下载 firebase 文件
- c++ - std::cout 正在减少 CPU 使用率?
- c# - 如何像在 Wii Tanks 中一样向移动方向旋转坦克主体 - Unity
- java - 在java中的字符串值之前添加前缀
- aql - 当我从文档中编写一个代码时出现莫名其妙的语法错误
- ios - iOS Metal的MTLTexture中的depth和arrayLength有什么区别
- go - 使用互斥锁 - 仍然是死锁
- airflow - 解析 dag 失败在 Cloud Composer 上找不到模块 slackclient