java - get table span class content using jsoup -
i have website contains table similar(bigger..) one:
</table> <tr> <td> <table width="100%" cellspacing="-1" cellpadding="0" border="0" dir="rtl" style="padding-top: 25px;"> <tr> <td align="right" style="padding-right: 25px;"> <span class="artist_name_txt"> <a href="/namelink">name</a> <p class="diccografia">subname</p> </span> </td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0" dir="rtl" style="padding-right: 25px; padding-left: 25px"> <tr> <td class="songs" align="right"> <a href="/number1link" class="artist_player_songlist"> number1</a> </td> </tr> <tr> <td class="songs" align="right"> <a href="/number2link" class="artist_player_songlist">number2</a> ....... </td> </tr> </table>
and need idea how can parse website , extract table 2 arrays -
- one names{number1, number2}
- and second links{number1link, number2link}
i tried lot of ways , nothing helps me.
you should read jsoup cookbook - selector syntax powerful.
here's example:
final string html = ... // use connect().get() instead if connect website document doc = jsoup.parse(html); list<string> names = new arraylist<>(); list<string> links = new arraylist<>(); for( element element : doc.select("a.artist_player_songlist") ) { names.add(element.text()); links.add(element.attr("href")); } system.out.println("names: " + names); system.out.println("links: " + links);
output:
names: [number1, number2] links: [/number1link, /number2link]
Comments
Post a Comment