How to get the pure raw HTML of a page in HTMLUnit while ignoring JavaScript and CSS?

 ̄綄美尐妖づ 提交于 2019-11-28 12:24:34
Mosty Mostacho

I think the closest thing to what you're looking for is:

WebClient webClient = new WebClient();
webClient.setCssEnabled(false);
webClient.setAppletEnabled(false);
webClient.setJavaScriptEnabled(false);

For HtmlUnit 2.13 and above, use webclient.getOptions().

Also this question and answer might be useful too. It really made things faster for me, but I had to recompile HtmlUnit...

Finally, in order to get the original content of the page (instead of the output of asXml()) try the following:

WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://www.yourpage.com");
String originalHtml = page.getWebResponse().getContentAsString();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!