Chrome无法启动,而是崩溃了

时间:2019-08-21 19:48:17

标签: python selenium-chromedriver ubuntu-16.04

我的任务是为应用制作一个简单的刮板。我能够在本地运行它,但是在服务器上运行(Ubuntu 16.04)时,我遇到了很多错误,最新错误是selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:崩溃。令人非常奇怪的是,在此混乱之前,脚本实际上只让我惊讶一次,然后才再次出错。

我已经尝试了其他解决方案,例如确保chromedriver-chrome版本匹配,卸载以重新安装,添加无头参数,指定.exe的路径。这只会导致一遍又一遍地重复出现相同的错误。

from bs4 import BeautifulSoup
from selenium import webdriver
import json
from selenium.webdriver.chrome.options import Options

# Adjusting selenium to a headless browser      
options = webdriver.ChromeOptions()
options.binary_location = '/usr/bin/google-chrome'
PATH = '/usr/local/bin/chromedriver'
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')


# Automating the Login straight to the Table
browser = webdriver.Chrome(executable_path=PATH, chrome_options=options)
browser.implicitly_wait(10) # delay to let js render
url = "site"
browser.get(url)
username = browser.find_element_by_id("UserName") #username form field
password = browser.find_element_by_id("Password") #password form field
username.send_keys("USER")
password.send_keys("PASS")
log_button = browser.find_element_by_id("login")
log_button.click()

# the code after is the scraper which is functioning

该脚本最终应该登录到页面并从表中抓取某些信息。

0 个答案:

没有答案