使用android中的Jsoup在脚本标记内获取文本

时间:2016-11-29 11:45:32

标签: java android jsoup

如何使用Jsoup获取值http://htvlive.1c656bad.cdnviet.com/fcf0d4d9ebc07ce9de74aff5562e4d2d1480305561/htv7.720p.stream/playlist.m3u8

nondescript screen shot

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("-------------------");
}

1 个答案:

答案 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();
}
相关问题