【问题标题】:Selenium 4 add Binary pathSelenium 4 添加二进制路径
【发布时间】:2022-07-16 10:59:43
【问题描述】:

早上好,我使用 selenium 进行了一些网页抓取,直到昨天一切正常,现在我得到这个错误,我知道这是由于更新二进制文件,但由于我想分享程序,我想要二进制文件在我创建的文件夹中,以便它与打开程序的人一起使用。 这是代码:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service
from selenium.webdriver.support.ui import WebDriverWait


# options
options = Options()
options.use_chromium = True
options.add_argument("--headless")
options.add_argument("disable-gpu")
options.add_argument('--allow-running-insecure-content')
options.add_argument('--ignore-certificate-errors')
options.add_experimental_option('excludeSwitches', ['enable-logging'])


# Selenium driver path
s=Service("./Monatseinteilung/driver/msedgedriver.exe")

driver = webdriver.Edge(service=s, options=options)

这是错误: selenium.common.exceptions.SessionNotCreatedException:消息:会话未创建:此版本的 MSEdgeDriver 仅支持 MSEdge 版本 100 当前浏览器版本为 102.0.1245.30,二进制路径为 C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe

【问题讨论】:

  • 您的驱动版本与您的浏览器不兼容:浏览器版本:102。驱动版本:100

标签: python selenium path binary


【解决方案1】:

您必须更改您的 msedgedriver.exe 驱动程序以匹配您在计算机上安装的 MS Edge 版本 (102)。您可以从here 下载。替换你的msedgedriver.exe,这个脚本应该开始工作了。每次 MS Edge 更新时,您都必须这样做。

由于您使用的是 Python,并且您想共享程序,这可能不是很方便。因此,您可以尝试使用诸如 selenium_driver_updater 或 webdriver_auto_update 之类的库,尽管 webdriver_auto_update 似乎只支持 Chrome。之后,您可以在每次运行脚本时检查可用的最新驱动程序

对于selenium_driver_updater

filename = DriverUpdater.install(path=base_dir, driver_name=DriverUpdater.chromedriver, upgrade=True, check_driver_is_up_to_date=True, old_return=False)
driver = webdriver.Chrome(filename)

对于webdriver_auto_update:

check_driver('folder/path/of/your/chromedriver')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    • 2017-06-24
    相关资源
    最近更新 更多