我需要在Python中以自动方式允许flash内容。我尝试在Python中使用Selenium,但是无法管理。问题是浏览器停止支持始终允许flash内容的设置。此外,例如,“不允许”按钮不能通过Selenium访问,因为它不是网站的一部分,也不是Firefox中的设置。有人知道潜在的解决方法吗?
Python:如何在Firefox中自动“允许” Flash Player内容?
•
问答
timberjack 回答:Python:如何在Firefox中自动“允许” Flash Player内容?
“ ...例如,
Allow
按钮无法通过Selenium访问,因为它不是网站的一部分,也不是Firefox中的设置。有人知道潜在的解决方法吗?”
我不知道您的操作系统,但是如果这是我的问题...
-
尝试查找“按键”模块,以将
A
按键发送到Firefox(即Allow
快捷方式)。 -
尝试在
Allow
按钮的坐标处单击鼠标。
一个不错的选择是pyautogui。通过此类模块(单击器或压片器)启用Flash后,您就可以在启用的Flash中进行Selenium的任何操作。
,要通过Python使用What is Selenium and what is WebDriver?以自动化的方式允许 flash 内容,您需要使用FirefoxProfile()
和set_preference()
方法的实例进行配置:>
-
dom.ipc.plugins.enabled.libflashplayer.so
到true
-
plugin.state.flash
到2
代码块:
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()