您能否建议我如何使用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]"));
        }


但是结果是完整的字符串:

输入type =“ hidden” id =“ song-path-8365” value =“ resources / audio / songs / 73742facb924e6.mp3” />
输入type =“ hidden” id =“ song-name-left-8365” value =“ Future Is Now” />
输入type =“ hidden” id =“ song-name-right-8365” value =“ Green Grey” />

我确定还有其他(更简便,更正确的方法)可以解决此问题,因此,我们将不胜感激

最佳答案

Elements inputs = document.select("input");
for(Element input:inputs){
    System.out.println(input.attr("value"));
}

关于java - Jsoup解析(正则表达式),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42363289/

10-12 06:52