我想从android studio的网页上获取一些信息

时间:2017-05-28 16:47:30

标签: android jsoup

我想从我的Android应用程序中获取以下HTML代码中的sometitle和somelink ... 帮助我:(

<div class="proper-list list-group page-cat-wrap">
  <figure class="col-md-12 thumb-vertical">
  <div class="col-xs-4 thumb-image">
  <a href="/somelink.html" class="image-hover">
    <img alt="SomeTag" src="/storage/images/100/2382.jpg">
  </a>
</div>
<figcaption class="col-xs-8">
  <h3>
    <a href="/somelink.html">
      SomeTitle
    </a>
  </h3>
  <p>
    <a href="/secondlink.html">
    SomeText
    </a>
  </p>
</figcaption>
<div class="clearfix"></div>
<div class="mobile-only icon-right">
  <a href="/somelink.html">
  <i class="fa fa-chevron-right" aria-hidden="true"></i>
  </a>
</div>

我听说过jsoup,但无法获得与jsoup的链接。

1 个答案:

答案 0 :(得分:1)

Jsoup是解析任何HTML内容或文档的最佳库, 这是链接和示例,

http://jsoup.org/

示例

private void parsehtmlPage(){
        File input = new File("/yourFolder/home.html");
        Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
        Element elementId = doc.getElementById("elementId");
        Elements ankerLinks = elementId.getElementsByTag("a");
        for (Element link : ankerLinks) {
            String linkHref = link.attr("href");
            String linkText = link.text();
        }
    }