如何使用 python 用勇敢的浏览器启动 selenium web 驱动程序

问题描述

我的铬版本是 87.0.4280.88

我勇敢的浏览器版本是87.0.4280.101

我尝试了很多代码,但它们都不起作用。

代码

from selenium import webdriver

option = webdriver.ChromeOptions()
option.binary_location = r'C:\Program Files (x86)\BraveSoftware\Brave- 
browser\Application\brave.exe'
driver = webdriver.Chrome(
executable_path=r'C:\WebDrivers\chromedriver.exe',options=option)
driver.get("https://www.google.com")

错误回溯:

Traceback (most recent call last):
File "c:\Users\MOHSEN\Desktop\test\Untitled-1.py",line 5,in <module>
driver = webdriver.Chrome(
TypeError: __init__() got an unexpected keyword argument 'options'

解决方法

要使用 驱动的 Selenium 启动 WebDriver 浏览会话,您可以使用以下解决方案:

  • 代码块:

    from selenium import webdriver
    
    option = webdriver.ChromeOptions()
    option.binary_location = r'C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe'
    driver = webdriver.Chrome(executable_path=r'C:\WebDrivers\chromedriver.exe',options=option)
    driver.get("https://www.google.com")
    
  • 浏览器快照:

Brave