java - Get data from table(html) except div tag by jsoup -


i have html code:

<table width="100%" cellpadding="5" cellspacing="2" class="zebra">    <tr>    <td colspan="5">     <div class="paginator">      <a href="http://some_link">2</a>&nbsp;              </div>     </td>   </tr>      <tr>     <td><a href="//i_need_only_this_link">some_value</a></td>          </tr>    <tr>          <td><a href="//i_need_only_this_link1">some_value</a></td>          </tr>    <tr>    <td colspan="2">     <div class="paginator">              <a href="http://some_link">2</a>&nbsp;     </div>     </td>   </tr>  </table> 

i use jsoup. how can links except links in div tag? try this, doesn't work. element contains links.

org.jsoup.nodes.elements tabletext = doc.select("table.zebra").not("tr td div.paginator");  (org.jsoup.nodes.element td : tabletext.select("td a")) {     system.out.println(td.attr("href")); // http://some_link     ....     } 

you can use below code..

document html = jsoup.parse(htmlstr);      (element e : html.getelementsbytag("a")) {          if (!"div".equalsignorecase(e.parentnode().nodename())) {             system.out.println(e.attr("href"));         }      } 

here checking parent node of anchor element not div. if not div printing url.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -