首页 > 解决方案 > Selenium 在打开后立即关闭浏览器

问题描述

我正在尝试使用 Selenium(在 Python 中)打开 Brave。它实际上会打开,但随后会立即关闭,并在控制台中出现以下错误:

[23340:9252:1107/063438.209:ERROR:os_crypt_win.cc(93)] 解密失败:参数错误。(0x57) [23340:9252:1107/063438.210:ERROR:brave_sync_prefs.cc(114)] 解密同步种子失败

DevTools 监听 ws://127.0.0.1:53809/devtools/browser/ecce3b0e-2884-4173-bdab-2215a3d7f507 [23340:9252:1107/063438.480:ERROR:CONSOLE(1)] "[Shields]: 不能请求为 tabId 屏蔽面板数据:2。错误:未指定选项卡 url”,来源:chrome-extension://mnojpmjdmbbfmejpflffifhffcmidifd/out/brave_extension_background.bundle.js (1)

我做了一些搜索,但找不到任何有用的东西。

这是我的代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

class Selen:
    def __init__(self):
        options = Options()
        service = Service("C:/Auxiliary/chromedriver_win32/chromedriver.exe")
        options.binary_location = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"
        self.driver = webdriver.Chrome(service=service, options=options)
        self.driver.get("https://google.com")

Selen()

我正在使用 Windows 11。

标签: pythonwindowsseleniumweb-scrapingbrave

解决方案


首先,您是否安装了 chrome,其次,如果您这样做,它是否有效?

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

class Selen:
    def __init__(self):
        options = Options()
        path = "C:/Auxiliary/chromedriver_win32/chromedriver.exe"
        self.driver = webdriver.Chrome(executable_path=path, options=options)
        self.driver.get("https://google.com")
        time.sleep(20)
        driver.close()

instance = Selen()

如果它确实有效,试试这个让它勇敢地工作,

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

class Selen:
    def __init__(self):
        options = Options()
        options.binary_location = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"
        path = "C:/Auxiliary/chromedriver_win32/chromedriver.exe"
        self.driver = webdriver.Chrome(executable_path=path, options=options)
        self.driver.get("https://google.com")
        time.sleep(20)
        driver.close()

instance = Selen()


推荐阅读