java - Parsing HTML with Jsoup -


i'm trying parsing , i'm stuck... here's structure of html:

<ul class="sub-menu">  <li id="1" class="1"><a href="http://link">some text</a>      <ul class="sub-menu">          <li .... ><a ... /></li>         <li .... ><a ... /></li>         <li .... ><a ... /></li>     </ul> </li> <li id="2" class="2"><a href="http://link2">some other text</a>      <ul class="sub-menu">          <li .... ><a ... /></li>         <li .... ><a ... /></li>         <li .... ><a ... /></li>     </ul> </li></ul> 

i need each li (id = 1, 2 , s) , lis inside them (<li .... ><a ... /></li>).

here's how java looks:

// ul contains source above elements lis = ul.select("li"); // know line screws here, can't figure out how correctly for(element li: lis) {     string text = li.select("a").first().text();     elements lis2 = li.select("ul[class=sub-menu]").first().getelementsbytag("li");          for(element li2: lis2)     {         element = li2.select("a").first();         // , other stuff 'a'     } } 

so can me solve problem?

edit: problem ul.select("li"); returns every single 'li' in source wrote here. need lis id 1, 2 , on. , need <li .... ><a ... /></li>. p.s. sorry bad english.

i'm not sure, try

for( element element : doc.select("[li]") ) {     if( element.attr("id")== 1 || element.attr("id").getvalue()== 2 )     {         // thats elements 'element'         system.out.println(element);     } } 

regards, hugo pedrosa


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -