Program WebClient WebClient = new WebClient (browserversion.chrome); Webclient.getoptions (). setjavascriptenabled (False ); Webclient.getoptions (). setcssenabled (false); HtmlPage page;try {page = Webclient.getpage ("http://www.taolife.com.cn/"); System.out.print (Page.astext ());} catch (Failinghttpstatuscodeexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} catch ( Malformedurlexception e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Auto-gene Rated catch Blocke.printstacktrace ();}
Bug:
1exception in thread "Main" java.lang.outofmemoryerror: java heap spaceat  JAVA.LANG.CLASS.GETDECLAREDFIELDS0 (Native method) At java.lang.class.privategetdeclaredfields ( class.java:2583) at java.lang.class.getfield0 (class.java:2975) At java.lang.class.getfield (Class.java : 1701) At com.gargoylesoftware.htmlunit.javascript.javascriptengine.configureconstants ( javascriptengine.java:612) At com.gargoylesoftware.htmlunit.javascript.javascriptengine.init ( javascriptengine.java:271) at com.gargoylesoftware.htmlunit.javascript.javascriptengine.access$000 ( javascriptengine.java:105) At com.gargoylesoftware.htmlunit.javascript.javascriptengine$1.run ( javascriptengine.java:173) At net.sourceforge.htmlunit.corejs.javascript.context.call (Context.java:628) at net.sourceforge.htmlunit.corejs.javascript.contextfactory.call (contextfactory.java:513) at Com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.initialize (JAVASCriptengine.java:184) at com.gargoylesoftware.htmlunit.webclient.initialize (WebClient.java:1008) at Com.gargoylesoftware.htmlunit.WebWindowImpl.setEnclosedPage (webwindowimpl.java:135) at Com.gargoylesoftware.htmlunit.html.FrameWindow.setEnclosedPage (framewindow.java:105) at Com.gargoylesoftware.htmlunit.html.HTMLParser.parse (htmlparser.java:221) at Com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml (htmlparser.java:199) 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:476) at Com.gargoylesoftware.htmlunit.WebClient.getPage (webclient.java:350) at Com.gargoylesoftware.htmlunit.html.BaseFrameElement.loadInnerPageIfPossible (baseframeelement.java:184) at Com.gargoylesoftware.htmlunit.html.BaseFrameElement.loadInnerPage (Baseframeelement.java:122) At com.gargoylesoftware.htmlunit.html.htmlpage.loadframes (HtmlPage.java:1945) at Com.gargoylesoftware.htmlunit.html.HtmlPage.initialize (htmlpage.java:227) at Com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto (webclient.java:483) at Com.gargoylesoftware.htmlunit.WebClient.getPage (webclient.java:350) at Com.gargoylesoftware.htmlunit.html.BaseFrameElement.loadInnerPageIfPossible (baseframeelement.java:184) at Com.gargoylesoftware.htmlunit.html.BaseFrameElement.loadInnerPage (baseframeelement.java:122) at Com.gargoylesoftware.htmlunit.html.HtmlPage.loadFrames (htmlpage.java:1945) at Com.gargoylesoftware.htmlunit.html.HtmlPage.initialize (htmlpage.java:227) at Com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto (webclient.java:483) at Com.gargoylesoftware.htmlunit.WebClient.getPage (webclient.java:350)
Modify the operating Parameters:-xms1024m-xmx1024m, still error.
Modify
Webclient.getoptions (). setjavascriptenabled (false);
Normal operation of the program;
Analysis:
It is estimated that there is a problem with the JavaScript parser used by Htmunit, which runs out of memory.
For project time issues, temporarily collect true scheme, back with Memory Monitor tool jconsole or Eclipse Memoery Analyzer to find out which module problem.
Htmlunit out of memoery Error:java heap space