如何使用Jsoup获取值http://htvlive.1c656bad.cdnviet.com/fcf0d4d9ebc07ce9de74aff5562e4d2d1480305561/htv7.720p.stream/playlist.m3u8
?
String url = "htvonline.com.vn/livetv/htv7-hd-34336E61.html";
Document document = Jsoup.connect(url).get();
Elements scriptElements = document.getElementsByTag("script");
for (Element element :scriptElements ){
for (DataNode node : element.dataNodes()) {
System.out.println(""+node.getWholeData().toString());
}
System.out.println("-------------------");
}
答案 0 :(得分:1)
与ID为li
的{{1}}元素中的网址相同,因此请选择该元素并阅读play_video
属性。
示例代码
data-source
<强>输出强>
try {
String userAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36";
Document doc = Jsoup.connect("http://htvonline.com.vn/livetv/htv7-hd-34336E61.html").userAgent(userAgent).get();
String url = doc.select("#play_video").first().attr("data-source");
System.out.println(url);
} catch (IOException e) {
e.printStackTrace();
}