谢谢你查看我的问题
用htmlunit请求页面时失败
"http://passport2.chaoxing.com/login?fid=&refer="
用谷歌浏览器访问却正常
用htmlunit2.3和htmlunit2.27都是这样
麻烦能够帮我找一下原因吗
代码:
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 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
1 2 3 4 5 6 | 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)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 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