HtmlUnit请求页面抛出异常

发布于 2022-09-07 07:51:45 字数 12008 浏览 25 评论 0

谢谢你查看我的问题

用htmlunit请求页面时失败
"http://passport2.chaoxing.com/login?fid=&refer="
用谷歌浏览器访问却正常
用htmlunit2.3和htmlunit2.27都是这样

麻烦能够帮我找一下原因吗

代码:
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {

        webClient.setJavaScriptTimeout(5000);
        webClient.getOptions().setDoNotTrackEnabled(false);
        webClient.getOptions().setUseInsecureSSL(true);//接受任何主机连接 无论是否有有效证书
        webClient.getOptions().setCssEnabled(false);
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
        webClient.getOptions().setTimeout(100000);//设置连接超时时间
        webClient.getCookieManager().setCookiesEnabled(true);
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());//很重要,设置支持AJAX
        System.out.println("js enabled:" + webClient.getOptions().isJavaScriptEnabled());

        System.out.println("css enabled:" + webClient.getOptions().isCssEnabled());
        HtmlPage page;
        page = webClient.getPage("http://passport2.chaoxing.com/login?fid=&refer=");
        sleep(15000);
        ps.print(page.asXml());
        ;
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    

报错信息:
"C:Program Files (x86)Javajdk1.8.0_112binjava" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:IntelliJ IDEA 2017.3.4libidea_rt.jar=23768:D:IntelliJ IDEA 2017.3.4bin" -Dfile.encoding=UTF-8 -classpath "D:IntelliJ IDEA 2017.3.4libidea_rt.jar;D:IntelliJ IDEA 2017.3.4pluginsjunitlibjunit-rt.jar;D:IntelliJ IDEA 2017.3.4pluginsjunitlibjunit5-rt.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibcharsets.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibdeploy.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextaccess-bridge-32.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextcldrdata.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextdnsns.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextjaccess.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextjfxrt.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextlocaledata.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextnashorn.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextsunec.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextsunjce_provider.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextsunmscapi.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextsunpkcs11.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibextzipfs.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibjavaws.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibjce.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibjfr.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibjfxswt.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibjsse.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibmanagement-agent.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibplugin.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibresources.jar;C:Program Files (x86)Javajdk1.8.0_112jrelibrt.jar;D:projectWebBrowseroutproductionWebBrowser;D:资源hamcrest-core-1.1.jar;D:资源hamcrest-library-1.1.jar;D:资源junit-4.11.jar;D:资源htmlunit-2.27libsac-1.3.jar;D:资源htmlunit-2.27libxalan-2.7.2.jar;D:资源htmlunit-2.27libhtmlunit-2.27.jar;D:资源htmlunit-2.27libcommons-io-2.5.jar;D:资源htmlunit-2.27libhttpcore-4.4.6.jar;D:资源htmlunit-2.27libhttpmime-4.5.3.jar;D:资源htmlunit-2.27libxml-apis-1.4.01.jar;D:资源htmlunit-2.27libcssparser-0.9.23.jar;D:资源htmlunit-2.27libhttpclient-4.5.3.jar;D:资源htmlunit-2.27libserializer-2.7.2.jar;D:资源htmlunit-2.27libcommons-codec-1.9.jar;D:资源htmlunit-2.27libcommons-lang3-3.5.jar;D:资源htmlunit-2.27libxercesImpl-2.11.0.jar;D:资源htmlunit-2.27libneko-htmlunit-2.27.jar;D:资源htmlunit-2.27libcommons-logging-1.2.jar;D:资源htmlunit-2.27libhtmlunit-core-js-2.27.jar;D:资源htmlunit-2.27libjetty-io-9.4.5.v20170502.jar;D:资源htmlunit-2.27libjetty-http-9.4.5.v20170502.jar;D:资源htmlunit-2.27libjetty-util-9.4.5.v20170502.jar;D:资源htmlunit-2.27libjetty-client-9.4.5.v20170502.jar;D:资源htmlunit-2.27libwebsocket-api-9.4.5.v20170502.jar;D:资源htmlunit-2.27libwebsocket-client-9.4.5.v20170502.jar;D:资源htmlunit-2.27libwebsocket-common-9.4.5.v20170502.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 Main.MainClass,Chaoxing
js enabled:true
css enabled:false
五月 11, 2018 9:13:12 下午 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
严重: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: :x).] sourceName=[http://passport2.chaoxing.com...] line=[2] lineSource=[null] lineOffset=[0]
五月 11, 2018 9:13:12 下午 com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController processSynchron
信息: Re-synchronized call to http://passport2.chaoxing.com...

java.lang.StackOverflowError

at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit_r(NodeTransformer.java:412)
at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit_r(NodeTransformer.java:412)
at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit_r(NodeTransformer.java:412)
at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit_r(NodeTransformer.java:412)
at 
                             ...

net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit_r(NodeTransformer.java:412)

at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit_r(NodeTransformer.java:412)
at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit_r(NodeTransformer.java:412)
at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit_r(NodeTransformer.java:412)
at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit_r(NodeTransformer.java:412)
at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transformCompilationUnit(NodeTransformer.java:56)
at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transform(NodeTransformer.java:32)
at net.sourceforge.htmlunit.corejs.javascript.NodeTransformer.transform(NodeTransformer.java:35)
at net.sourceforge.htmlunit.corejs.javascript.CodeGenerator.compile(CodeGenerator.java:60)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.compile(Interpreter.java:189)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2698)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1632)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:214)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1624)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:716)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:879)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:637)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:518)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:725)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:691)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:737)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScript(HtmlPage.java:918)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:317)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:382)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:247)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:268)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:800)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:756)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1236)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1136)
at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:226)
at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:345)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3178)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2141)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:945)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:521)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:472)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:999)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:250)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:192)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:272)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:160)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:522)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:396)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:313)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:461)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:446)
at Main.MainClass.Chaoxing(MainClass.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Process finished with exit code -1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文