我似乎无法让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浏览器和Chromedriver之间有什么区别?我过去曾使用Chromedriver登录Chrome与Selenium一起使用。
您需要将可执行路径设置为chromedriver
,因为这是selenium
使用的路径。所以这行代码需要是:
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', chrome_options=options)