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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -