java - OutOfMemoryError while using HtmlUnit for scrapping -


i using htmlunit login on site , download data table

when run code is causing java.lang.outofmemoryerror , not run further.

following code :

webclient webclient = new webclient(browserversion.internet_explorer_6); webclient.getoptions().setjavascriptenabled(true); webclient.getoptions().setcssenabled(false); webclient.getoptions().setredirectenabled(true); webclient.getcookiemanager().setcookiesenabled(true);                             webclient.getoptions().setprintcontentonfailingstatuscode(false); webclient.setajaxcontroller(new nicelyresynchronizingajaxcontroller()); webclient.getoptions().settimeout(50000); webclient.getoptions().setuseinsecuressl(true); webclient.getoptions().setpopupblockerenabled(true);  htmlpage htmlpage=webclient.getpage(url); thread.sleep(200);                             //~~~~~~~log-in htmltextinput uname=(htmltextinput)htmlpage.getfirstbyxpath("//*[@id=\"username\"]"); uname.setvalueattribute("xxx"); htmlpasswordinput upass=(htmlpasswordinput)htmlpage.getfirstbyxpath("//*[@id=\"password\"]"); upass.setvalueattribute("xxx"); htmlsubmitinput submit=(htmlsubmitinput)htmlpage.getfirstbyxpath("//*[@id=\"login-button\"]/input"); htmlpage=(htmlpage) submit.click(); thread.sleep(200); webclient.waitforbackgroundjavascript(10000); (int = 0; < 250; i++) {  if (!htmlpage.astext().contains("loading...")) {      break;   }     synchronized (htmlpage) {      htmlpage.wait(500);  } }  system.out.println(htmlpage.astext()); 

and following stacktrace

java.lang.outofmemoryerror: java heap space @ net.sourceforge.htmlunit.corejs.javascript.node.newstring(node.java:155) @ net.sourceforge.htmlunit.corejs.javascript.node.newstring(node.java:151) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.createpropertyget(irfactory.java:1990) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformpropertyget(irfactory.java:968) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:106) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformpropertyget(irfactory.java:964) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:106) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformpropertyget(irfactory.java:964) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:106) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformfunctioncall(irfactory.java:595) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:86) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transforminfix(irfactory.java:775) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:161) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformassignment(irfactory.java:368) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:152) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformexprstmt(irfactory.java:488) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:149) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformblock(irfactory.java:406) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:82) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformif(irfactory.java:762) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:110) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformblock(irfactory.java:406) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:82) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformif(irfactory.java:762) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:110) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformblock(irfactory.java:406) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:82) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformif(irfactory.java:768) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:110) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformblock(irfactory.java:406) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transform(irfactory.java:82) @ net.sourceforge.htmlunit.corejs.javascript.irfactory.transformfunction(irfactory.java:560) 

i have put follwoing lines in catlina.sh file allot heap memory still getting same error (my ram size 2gb).

if [ -z "$logging_manager" ];      java_opts="$java_opts -djava.util.logging.manager=org.apache.juli.classloaderlogmanager" else      java_opts="$java_opts $logging_manager" fi  # uncomment following line make umask available when using # org.apache.catalina.security.securitylistener    java_opts="$java_opts -dorg.apache.catalina.security.securitylistener.umask=`umask`"    java_opts="$java_opts  -xms512m -xmx2048m -xx:maxpermsize=512m"    java_opts="-server -xx:+useconcmarksweepgc" 

you include $java_opts @ last line of code,may code works

java_opts="$java_opts -server -xx:+useconcmarksweepgc" 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -