gpt4 book ai didi

python - 如何将 Brave 网络浏览器与 python、selenium 和 chromedriver 结合使用?

转载 作者:行者123 更新时间:2023-12-01 00:35:15 28 4
gpt4 key购买 nike

我从 Google Chrome 切换到 Brave web browser我很难让它与 Brave 一起工作,就像与 Chrome 一样。 Brave 是基于 Chromium 的,所以我猜它应该不会那么难。我确保我的 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

要检查 Brave 版本,我得到:版本 0.68.132 Chromium:76.0.3809.132(官方版本)(64 位)

然后我运行这段代码,

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

最佳答案

我终于成功了:

尝试这个 python 脚本 (python3.7)

from selenium import webdriver

driver_path = "C:/Users/username/PycharmProjects/chromedriver.exe"
brave_path = "C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"

option = webdriver.ChromeOptions()
option.binary_location = brave_path
# option.add_argument("--incognito") OPTIONAL
# option.add_argument("--headless") OPTIONAL

# Create new Instance of Chrome
browser = webdriver.Chrome(executable_path=driver_path, chrome_options=option)

browser.get("https://www.google.es")

干杯。

关于python - 如何将 Brave 网络浏览器与 python、selenium 和 chromedriver 结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57837496/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com