HtmlUnit takes lot of time to execute javascript, i would like to know if its possible to make HtmlUnit not to load javascript from url regex filters.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Not exactly, you can't only disable javascript as a whole (probably you already know it):
final WebClient webClient = new WebClient();
webClient.getOptions().setJavascriptEnable(false);
but you can use a ScriptPreProcessor the javascript, and erase what you don't want:
webClient.setScriptPreProcessor(new ScriptPreProcessor() {
@Override
public String preProcess(HtmlPage htmlPage, String sourceCode, String sourceName, int lineNumber, HtmlElement htmlElement) {
if (match...)
return "";
}
});