How to use Brave web browser with python, selenium and chromedriver?

Posted in :

如何透過 selenum 呼叫出brave 瀏覽器, 答案是用 option.binary_location = brave_path 即可.

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")

資料來源:
https://stackoverflow.com/questions/57837496/how-to-use-brave-web-browser-with-python-selenium-and-chromedriver


解法2:
https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/806

MattWaller commented on Sep 13, 2022 • edited 

Just make sure you point to browser_executable_path parameter. To make it run on Ubuntu for example.
import undetected_chromedriver as uc
driver = uc.Chrome(browser_executable_path='/usr/bin/brave-browser')

如果是 macOS 平台.

System:
macOS Catalina 10.15.2
Python 3.7.4
pytest 5.3.2
selenium 3.141.0
ChromeDriver 79.0.3945.36
Brave 1.1.23 Chromium: 79.0.3945.88 (Official Build) (64-bit)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
driver_path = '/usr/local/bin/chromedriver'
drvr = webdriver.Chrome(options = options, executable_path = driver_path)
drvr.get('https://stackoverflow.com')

Reference:
Set chrome browser binary through chromedriver in Python

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *