html parsing - how to get text between a specific span with HtmlUnit -


i'm new htmlunit , i'm not sure if right tool project. i'm trying parse website , extract values need it. need value "07:05" this,

<span class="tim tim-dep">07:05</span> 

i know can use gettextcontent() extracting value don't know how can select specific span. used getelementbyid finding the

<div> 

tag expression belongs when text content of div, whole line of text lot of unnecessary data. can tell me how can select expression, possibly using class name?

you need browse page , interact it, this:

final webclient web = new htmlunit(); final htmlpage page = web.getpage("http://www.whateveryouwant.com.br"); 

get elements tagname, , iterate on it:

final list<domelement> spans = page.getelementtagname("span"); (domelement element : spans) {     if (element.getattribute("class").equals("tim tim-dep")) {         return element.getnodevalue();     } } 

or use xpath:

// not sure getfirstbyxpath return domelement element = page.getfirstbyxpath("//span[@class='tim tim-dep']"); final string text = element.getnodevalue(); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -