WebClient webclient=NewWebClient (browserversion.chrome); Webclient.setjavascripttimeout (5000); Webclient.getoptions (). Setuseinsecuressl (true); Webclient.getoptions (). setjavascriptenabled (true); Webclient.getoptions (). setcssenabled (false); Webclient.getoptions (). Setthrowexceptiononscripterror (false); Webclient.getoptions (). SetTimeout (100000); Webclient.getoptions (). setdonottrackenabled (false); HtmlPage Page=webclient.getpage ( This. Path); Webclient.waitforbackgroundjavascript (20000); Thread.Sleep (5000); HTMLDivision Div= (htmldivision) Page.getelementbyid ("forecast"); String XML=Div.asxml (); if(Xml.indexof ("forecast-data-loading") >=0) {System.out.println ("Htmlunit parsing page failed"); } Else{System.out.println ("Htmlunit Parse page succeeded"); int[] aqis=New int[8]; intI=0; List<HtmlTable> tables= (list); if(Tables.size () ==8) { for(HtmlTable table:tables) {List<HtmlTableRow> trs= (list); HtmlTableRow TR=trs.get (0); intAqi=0; List<HtmlTableCell> cells = (list); for(HtmlTableCell cell:cells) {String s=Cell.astext (); String [] Values=s.split ("\ r \ n"); AQI=aqi+ (Integer.parseint (values[0)) +integer.parseint (values[1])/2 ; } AQI=aqi/cells.size (); Aqis[i]=AQI; I=i+1; } }
Java htmlunit Crawl Web page data