我从 Google 的 Chrome 切换到了Brave 网络浏览器,并且很难让它像在 Chrome 上那样与 Brave 一起工作。Brave 是基于铬的,所以我猜它不应该那么难。我确保我的 Brave 和 Chromedriver 在同一个版本上,像这样,
~/some/path $ chromedriver --version
ChromeDriver 76.0.3809.126 (d80a294506b4c9d18015e755cee48f953ddc3f2f-refs/branch-heads/3809@{#1024})
我的 chromedriver 也在/user/bin
,
~/path $ cd /usr/bin/
/usr/bin $ ls | grep chromedriver
chromedriver
为了检查勇敢的版本,我得到:Version 0.68.132 Chromium: 76.0.3809.132 (Official Build) (64-bit)
然后我运行这段代码,
from selenium import webdriver
driver = webdriver.Chrome(executable_path='/usr/bin/brave-browser')
driver.get("http://www.python.org")
driver.close()
这会打开一个 Brave 窗口,但不是获取驱动程序指向的页面,而是引发异常,
Traceback (most recent call last):
File "webscrap.py", line 3, in <module>
driver = webdriver.Chrome(executable_path='/usr/bin/brave-browser')
File "/home/username/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/home/username/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/username/.local/lib/python3.6/site-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/brave-browser unexpectedly exited. Status code was: -11