python - 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。
解决方案
首先,您是否安装了 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()
推荐阅读
- javascript - Firebase 云消息传递的 getToken() 在 Chrome 扩展中挂起
- angular - 手动向可观察对象发出值
- wpf - 在便笺中滚动
- javascript - 将第二个日期选择器设置在第一个日期选择器之前一年
- bash - 为什么调用 ${DIR} 时 DIR="$( cd "$( dirname "$( readlink "${BASH_SOURCE[0]}" )" )" && pwd )" 返回“没有这样的文件或目录”?
- database - 无法修改数据库字段
- html - 硬证明内容
- maven - Maven 依赖 - 问题
- c# - asp .net 中的第二个布局中的 RenderBody 错误
- javascript - 试图在 localhost 中为已经运行的服务器捕获客户端 IP 地址,但 node.js 与现有服务器冲突