修的了电脑 敲得了代码
     写得了前端 稳得住后端

关于selenium无法在chrome中自动播放flash的问题(终极解决办法),设置了开启flash也无法自动开启flash

网上很多的办法都是这样:

prefs = {
    "profile.managed_default_content_settings.images": 1,
    "profile.content_settings.plugin_whitelist.adobe-flash-player": 1,
    "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1,

}

chrome_options = Options()

chrome_options.add_argument('--no-sandbox')#解决DevToolsActivePort文件不存在的报错

chrome_options.add_argument('window-size=1920x1080') #指定浏览器分辨率
chrome_options.add_argument('--disable-gpu') #谷歌文档提到需要加上这个属性来规避bug
#chrome_options.add_argument('--hide-scrollbars') #隐藏滚动条, 应对一些特殊页面
#chrome_options.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度
chrome_options.add_argument('--headless') #浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
chrome_options.binary_location = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" #手动指定使用的浏览器位置
chrome_options.add_experimental_option('prefs', prefs)

但是这样设置仍然没有生效。

最近用selenium写个小脚本,遇到flash不能自动播放问题

我遇到的情况,直接提示 请确认是否安装flash,其实已经安装,点击下载flash,然后提示是否允许。 整了好久,发现终极方法:

## 71.0 以上 ##
从71.0开始,Flash插件的Ephemeral模式不可关闭。
修改允许名单,要动用“Chrome政策模板”,对Windows来说最终就是注册表。
请注意这是一项危险操作:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Policies\Google\Chrome\PluginsAllowedForUrls]
"1"="[*.]com"
"2"="[*.]net"
"3"="[*.]org"
"4"="[*.]cn"

 

把上面的代码保存成1.reg后,双击打开,再点击确定就可以了

Selenium设置flash

写入注册表后,重启Chrome。进入chrome://settings/content/flash即可看到效果。

赞(0)
未经允许不得转载:流云溪|码农 » 关于selenium无法在chrome中自动播放flash的问题(终极解决办法),设置了开启flash也无法自动开启flash