2016-06-25 5 views
0

Jsoups .selectを使用してPandoraからお気に入りの曲を抽出しようとしています。Jsoup .selectを使用した情報抽出

HTML:このJavaコードを使用して

<div class="user_feed clearfix"> 
    <div id="profile_tip_spacer">&nbsp;</div> 


     <!-- FEED ITEM START 6008047449161974 --> 
     <div class="section clearfix" 
      webname="genericprofile" 
      listenerId="1326689853" 
      feedId="6008047449161974" 
      feedIndex="1" 
             > 
      <div class="infobox"> 
       <div class="infobox-thumb"> 
        <div class="owner_profile_image"> 

          <a href="/profile/genericprofile"> 
           <div class="feed_profile pfora-img-square pfora-img-square--50x50" style="background-image:url(/img/no_listener_image.png)"></div> 
          </a> 

                               </div><!-- owner_profile_image --> 
       </div><!-- infobox-thumb --> 
       <div class="infobox-body"> 
        <div class="like_song feed_details clearfix"> 
                <h3 class="hed-4"> 
          <div class="newsfeed_text clearfix"><span class="user_name"><span class="user_name self"><a href="/profile/genericprofile" fbid="0" webname="genericprofile" class="facebookName">genericprofile</a></span> likes</span> <span class="newsfeed_song_name"><a href="/logic/man-of-year-single/man-of-year">Man Of The Year</a></span> <span>by</span> <span class="newsfeed_song_name"><a href="/logic">Logic</a></span><br /> 
           <ul class="list-h-1"> 

public static void main(String[] args) { 
    Document doc = null; 
    try { 
     doc = Jsoup.connect(
       "http://www.pandora.com/profile/genericprofile") 
       .get(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    Elements links = doc.select("div.user_feed.clearfix"); 
    String title = doc.title(); 
    System.out.println(title); 
    for (Element e : links) { 
     System.out.println(links); 
    } 

} 

}

私は最終的に私の最終目標はあるuser_feed clearfixクラスを表示することができましたが、

doc.select("div.user_feed.clearfix > div.section clearfix"); 

を使用してセクションclearfix要素のすべてを.selectすることができませんでしたソング名とアーティスト、この場合は「Logic」の「Man of the Year」を含むhrefリンクを取得し、Stringクラスを使用してそれを操作できます。

+0

2番目の 'clearfix'クラスセレクタに' .'を使用する必要がある空白を使用しました。 – fabian

+0

"。"空白の代わりに、私は残念ながらリンク変数に何も戻っていません。 –

答えて

0

あなたは使用する必要があります。

div.section.clearfix 

sectionclearfixのクラスとdivを選択します。

+0

div.section.clearfixを使用するたびに、出力しようとすると何も戻ってこない。 –

関連する問題