2017-01-24 72 views
0

我想從div.class YT-鎖止內容href屬性,但它返回null是我做錯了嗎?提取HREF從其他H3 /類類中的一類具有jsoup

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

我需要得到這個網址:href="/watch?v=8M00cos0d_0"

回答

2

一種選擇可能是閱讀後選擇屬性:

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

輸出:

/watch?v = 8M00cos0d_0

+0

它不適合我 – Hamza