2013-09-24 77 views
0

我是新手,試圖用Jsoup在Android中取消某個網站。 HTML元素的結構是這樣的:用jsoup在Android中刮開初學者

<div id="latest-article"> 
    <article> 
     <div class="post-text"> 
       <h3 class="title"> 
        <a href="links">article_title</a> 
       </h3> 
     </div> 
    </article> 
    <article> 
    ... 
    </article> 
    <article> 
    ... 
    </article> 
</div> 

我想獲得article-titlelinks,使我的文章的ListView的ArrayAdapter。

doc = Jsoup.connect("http://muslim.or.id").get(); 

    // get all articles 
    Elements articles = doc.select("div#latest-article"); 
    for (Element article : articles) { 
     ... 
    } 

在此先感謝。

回答

0

對不起,我小的努力:

Element latestArticle = doc.select("div#latest-article").first(); 
Elements articles = latestArticle.select("article"); 
for (Element article : articles) { 
    // get the value from href attribute 
    Element link = article.select("div.post-text > h3.title > a").first(); 
    String linkHref = link.attr("href"); 
    String linkText = link.text(); 

    System.out.println(linkText + " - " + linkHref); 
}