铬浏览器意外退出(Ubuntu服务器)

时间:2019-10-27 22:15:29

标签: python google-chrome ubuntu amazon-ec2 selenium-chromedriver

我似乎无法让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。我使用的驱动程序可能过时了吗?任何帮助表示赞赏,因为这一直使我疯狂,试图深入了解这一点!我也想知道:铬浏览器和chromedriver有什么区别?我过去曾使用chromedriver登录Chrome浏览器以与Selenium一起使用。谢谢!

1 个答案:

答案 0 :(得分:0)

您需要将可执行路径设置为<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>chart</title> </head> <body> <br> <br> <canvas id="canvas" width="400" height="400"></canvas> <style> canvas { border: 1px solid black; } </style> <script> window.onload = function canvas() { let canvas = document.getElementById('canvas'); let ctx = canvas.getContext('2d'); let data = [['A', 439], ['B', 228.23], ['C', 2580.39], ['D', 279]]; let barwidth = 50; let ygap = 30; let bargap = 100; let x = 50; y = canvas.height - ygap; canvas.width = data.length * (bargap) + x; ctx.moveTo(x - 5, y); ctx.lineTo(canvas.width, y); // Base line of graph ctx.stroke(); for (let i = 0; i < data.length; i++) { ctx.textAlign = 'left'; ctx.textBaseline = 'top'; ctx.fillStyle = 'black'; ctx.fillText(data[i][0], x, y + 5); // Write base text for classes ctx.beginPath(); ctx.lineWidth = 2; y1 = y - data[i][1]; // Coordinate for top of the Bar x1 = x; ctx.fillStyle = 'black'; ctx.fillText(data[i][1], x1, y1 - 20); // text at top of the bar ctx.fillStyle = 'black'; // fill Colur of bar ctx.fillRect(x1, y1, barwidth, data[i][1]);// Filled bar x += bargap } } </script> </body> </html> ,因为这是chromedriver使用的路径。因此该行代码必须为:

selenium