使用htmlunit时出错

时间:2015-01-13 08:14:26

标签: java htmlunit

我在java中使用 gargoylesoftware htmlunit 来运行javascript之后获取网页(因为您无法使用内置的java库执行此操作)。我在webscraper中使用它,所以这段代码运行了很多次而没有问题,但是随机运行程序后每隔一小时就会出现这个错误:

Jan 13, 2015 8:03:52 AM com.gargoylesoftware.htmlunit.WebConsole info
INFO: ThreadStats: couldn't get the catalog (undefined)
Jan 13, 2015 8:03:52 AM com.gargoylesoftware.htmlunit.WebConsole info
INFO: ThreadStats: couldn't get the catalog ()

出现错误的代码是:

final HtmlPage page = webClient.getPage(URIget.getSearchURL(ToSearch, board));

我非常确定错误并非来自我的URI.getSearchURL方法,因为它没有做任何奇特的事情,只是将几个字符串放在一起

1 个答案:

答案 0 :(得分:0)

在创建WebClient后尝试放置它们,它应该阻止消息显示

            webClient.setCssErrorHandler(new SilentCssErrorHandler());
            LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.html.HtmlScript").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.WindowProxy").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("org.apache").setLevel(Level.OFF);