[英]Parse Audio Src with JSoup
我正在尝试解析以下代码,并尝试从Audio元素中提取src属性。
<div id="jquery_jplayer_1" class="jp-jplayer" style="width: 0px; height: 0px;">
<img id="jp_poster_0" style="width: 0px; height: 0px; display: none;">
<audio id="jp_audio_0" preload="none" src="http://www.testurl.com/mp3embed-zg3t2s8n2ofl.mp3">
</audio>
</div>
我试图使用以下代码来解析它,但没有成功
Element link = doc.select("audio").first();
和
Element link = doc.select("#jp_audio_0");
这应该可以解决问题:
String html = \\your html..
Document doc =Jsoup.parseBodyFragment(html);
//Selects first "audio" element with id of "jp_audio_0" and gets the "src" attribute.
String src = doc.select("audio#jp_audio_0").first().attr("src");
System.out.println(src);
尝试这个:
String src = doc.select("audio[id=jp_audio_0]").first().attr("src");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.