问题
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