Reputation: 79
Could you please advise, how I can extract these messages using jsoup:
resources/audio/songs/73742facb924e6.mp3
Future Is Now
Green Grey
from this code:
<div class="playlist-item"
id="playlist-item-2"
data-song-id="8365"
onmouseover="javascript: pageUtils.playlistItemSharebar(2);"
onclick="jwPlayerUtils.playSong(8365, 2, event); _gaq.push(['_setAccount', 'UA-1091709-7']); _gaq.push(['_trackPageview']);">
<input type="hidden" id="song-path-8365" value="resources/audio/songs/73742facb924e6.mp3" />
<input type="hidden" id="song-mode-8365" value="song" />
<input type="hidden" id="song-name-left-8365" value="Future Is Now" />
<input type="hidden" id="song-name-right-8365" value="Green Grey" />
<input type="hidden" id="song-programName-8365" value="" />
<input type="hidden" id="song-img-8365" value="resources/img/songs/98x74_DIR/8365.jpg?201702161231" />
Here what I have already try:
Document document = Jsoup.connect(url).execute().parse();
Elements elements = document.select(".playlist-item");
for (Element element : elements) {
System.out.println("Artist: " + element.select("[id~=^song-name-right-[0-9]+$]").select("[value]"));
System.out.println("Song: " + element.select("[id~=^song-name-left-[0-9]+$]").select("[value]"));;
System.out.println("Link: " + element.select("[id~=^song-path-[0-9]+$]").select("[value]"));
}
But the result is full string:
input type="hidden" id="song-path-8365" value="resources/audio/songs/73742facb924e6.mp3" /> input type="hidden" id="song-name-left-8365" value="Future Is Now" /> input type="hidden" id="song-name-right-8365" value="Green Grey" />
I'm sure that there is some other (easier and more correct) way to cope with this, so will appreciate any help
Upvotes: 2
Views: 314
Reputation: 3401
Elements inputs = document.select("input");
for(Element input:inputs){
System.out.println(input.attr("value"));
}
Upvotes: 1