How to enable Flash to HTMLUnit?

耗尽温柔 提交于 2019-12-08 04:11:21

问题


I'm trying to grab html contents by HTMLUnit. Everything went nice, but couldn't get Flash contents those are visible as <img> where its actually in <object>, i have

   webClient.getOptions().setJavaScriptEnabled(true);
   webClient.getOptions().setActiveXNative(true);
   webClient.getOptions().setAppletEnabled(true);
   webClient.getOptions().setCssEnabled(true);

In SO some places i found someone saying HTMLUnit won't support Flash, but those answers seems old, so am raising this question. Someone please help. Thanks.


回答1:


I found it with the help for this i have downgrade my HTMLUnit version from 2.15 to 2.13 as in 2.15 BrowserVersionFeatures.JS_FRAME_RESOLVE_URL_WITH_PARENT_WINDOW seems deprecated and don't know what feature replaced here.

   private static BrowserVersion firefox17WithUptoDateFlash = new BrowserVersion(BrowserVersion.FIREFOX_17.getApplicationName(),        BrowserVersion.FIREFOX_17.getApplicationVersion(),        BrowserVersion.FIREFOX_17.getUserAgent(),        BrowserVersion.FIREFOX_17.getBrowserVersionNumeric(),new BrowserVersionFeatures[]{
    BrowserVersionFeatures.JS_FRAME_RESOLVE_URL_WITH_PARENT_WINDOW,
    BrowserVersionFeatures.STYLESHEET_HREF_EXPANDURL,
    BrowserVersionFeatures.STYLESHEET_HREF_STYLE_NULL
});
static {
    PluginConfiguration plugin1 = new PluginConfiguration(
            "Shockwave Flash",
            "Shockwave Flash 11.4 r402",
            "NPSWF32_11_4_402_287.dll");
    plugin1.getMimeTypes().add(new PluginConfiguration.MimeType(
            "application/x-shockwave-flash", 
            "Adobe Flash movie",
            "swf"));
    firefox17WithUptoDateFlash.getPlugins().add(plugin1);
}
   final WebClient webClient = new WebClient(firefox17WithUptoDateFlash);

Here newly written browser instance will give support to htmlunit to act as flash enabled GUI-less browser



来源:https://stackoverflow.com/questions/24995989/how-to-enable-flash-to-htmlunit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!