【发布时间】:2017-07-10 20:06:22
【问题描述】:
您能否建议我如何使用 jsoup 提取这些消息:
资源/音频/歌曲/73742facb924e6.mp3
未来就是现在
绿灰色
从此代码:
<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" />
这是我已经尝试过的:
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]"));
}
但结果是完整的字符串:
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" />
我确信还有其他一些(更简单、更正确)的方法可以解决这个问题,因此将不胜感激
【问题讨论】:
-
你要提取什么??
-
@RamanSahasi,这是正则表达式:“[id~=^song-name-right-[0-9]+$]”
-
@thanga,我需要提取“resources/audio/songs/73742facb924e6.mp3,Future Is Now,Green Grey”我在按摩中写的。我写了我需要的东西,以及我需要的地方。
-
尝试输入.attr("value")