【问题标题】:Python: How to automate 'Allow' flash player content in Firefox?Python:如何在 Firefox 中自动化“允许”Flash 播放器内容?
【发布时间】:2019-12-02 10:09:54
【问题描述】:

我需要在 Python 中以自动方式允许 Flash 内容。我尝试在 Python 中使用 Selenium 来执行此操作,但无法管理。问题是浏览器停止支持始终允许 Flash 内容的设置。此外,例如,“允许”按钮不能通过 Selenium 访问,因为它不是网站的一部分或 Firefox 中的设置。有人知道潜在的解决方法吗?

这是我需要以某种方式访问​​的 Firefox 消息的图像:

【问题讨论】:

  • 您是否检查过是否有始终允许的选项?
  • 遗憾的是,他们在 2017 年删除了此选项。

标签: python selenium firefox flash firefox-profile


【解决方案1】:

“...Allow 按钮无法通过 Selenium 访问,因为它不是网站的一部分或 Firefox 中的设置。有人知道潜在的解决方法吗?”

我不知道你的操作系统,但如果这是我的问题...

  • 尝试找到一个“按键”模块将A按键发送到Firefox(即:Allow快捷方式)。

  • 尝试在Allow按钮的坐标处发送鼠标点击。

pyautogui 是一个不错的尝试选择。一旦此类模块(点击器或按压器)启用了 Flash,您就可以让 Selenium 参与您需要在启用的 Flash 中执行的任何操作。

【讨论】:

    【解决方案2】:

    要通过 Python 以自动方式使用 Selenium 允许 flash 内容,您需要使用 FirefoxProfile()set_preference() 方法的实例进行配置:

    • dom.ipc.plugins.enabled.libflashplayer.sotrue
    • plugin.state.flash2

    代码块:

    from selenium import webdriver
    
    profile = webdriver.FirefoxProfile()
    profile.set_preference("dom.ipc.plugins.enabled.libflashplayer.so","true")
    profile.set_preference("plugin.state.flash", 2)
    driver = webdriver.Firefox(firefox_profile=profile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
    driver.get('https://www.google.co.in')
    print("Page Title is : %s" %driver.title)
    driver.quit()
    

    【讨论】:

    • 此解决方案不再适用于 Firefox 和其他浏览器,因为无法再为 Flash 内容设置这些首选项。
    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 2019-07-07
    • 1970-01-01
    • 2017-05-11
    • 2014-02-12
    • 2017-09-23
    • 2017-03-22
    • 2015-08-20
    相关资源
    最近更新 更多