gpt4 book ai didi

java - HtmlUnit 忽略配置并抛出异常

转载 作者:行者123 更新时间:2023-12-01 11:00:32 24 4
gpt4 key购买 nike

HtmlUnit 仍然会根据 JS 错误抛出异常。我试过了

    webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);

但还是返回

ERROR c.g.htmlunit.html.HtmlPage - Error loading JavaScript from [http://example.com/mobilenew/js/jquery.mobile.swipe.min.js].
java.io.IOException: Unable to download JavaScript from 'http://example.com/mobilenew/js/jquery.mobile.swipe.min.js' (status 404).
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:1082) ~[htmlunit-2.18.jar:2.18]
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1009) ~[htmlunit-2.18.jar:2.18]
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:395) [htmlunit-2.18.jar:2.18]
at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:276) [htmlunit-2.18.jar:2.18]
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:290) [htmlunit-2.18.jar:2.18]
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:800) [htmlunit-2.18.jar:2.18]
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) [xercesImpl-2.11.0.jar:na]
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:757) [htmlunit-2.18.jar:2.18]
at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170) [nekohtml-1.9.22.jar:1.9.22]
at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072) [nekohtml-1.9.22.jar:1.9.22]

此错误仅出现在远程服务器上。在本地机器上,运行spock测试,htmlUnit工作正常。

最佳答案

尝试使用下面的这些

        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);

关于java - HtmlUnit 忽略配置并抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33362561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com