i developing java web application , want know how take field (table and/or output-text) value website. assuming component has same id know how can retrieve information? don't know if has ever faced issue if has idea please share. thank you.
in general: 1.) retrieve pages markup reading through httpconnection url in application 2.) parse markup using framework jsoup , retrieve value need.
more specifically, here example code jsoup:
httpclient http = new defaulthttpclient(); string htmlcode = ""; httpget request = new httpget("http://www.example.com"); httpresponse response = null; try { response = http.execute(request); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } if(response != null){ bufferedreader read = new bufferedreader(new inputstreamreader(response.getentity().getcontent())); string line = ""; while((line = read.readline()) != null){ htmlcode += line; } } // @ point have pages markup document doc = jsoup.parse(htmlcode); elements lis = doc.getelementsbytag("li"); // entries in lists for(element el : lis){ string val = el.text().trim(); // each list entry }
Comments
Post a Comment