使用jsoup从其他h3 / class类中的类中提取href

时间:2017-01-24 04:11:21

标签: java android html jsoup

我试图从 div.class yt-lockup-content 获取Range("A1").Copy属性,但它正在返回href我在做什么错?

null

到目前为止我尝试过这段代码:

<div class="yt-lockup-content">

        <h3 class="yt-lockup-title "><a class="yt-uix-sessionlink yt-uix-tile-link  spf-link  yt-ui-ellipsis yt-ui-ellipsis-2" dir="ltr" title="Live ::   PTV Sports Official Live Transmission"  data-sessionlink="ei=K8uGWMHkGMWjcp7dhNAJ&amp;feature=c4-live-promo" href="/watch?v=8M00cos0d_0">Live ::   PTV Sports Official Live Transmission</a></h3>

我需要获取此网址:rssDocument = Jsoup.connect("https://www.youtube.com/channel/UC0KT03NPnN-j4HGzetW9Lpw/featured").timeout(6000).ignoreContentType(true).parser(Parser.htmlParser()).get(); Elements firstH1 = rssDocument.select("div.yt-lockup-content > h3 > a");

1 个答案:

答案 0 :(得分:2)

选项可以是在select:

之后读取属性
Document doc = Jsoup.parse(html);
Elements link = doc.select("div.yt-lockup-content > h3 > a");
String hrefAttribute = link.attr("href");
System.out.println(hrefAttribute);

输出:

  

/观看?V = 8M00cos0d_0