【问题标题】:How to get all text from divs that have class="title" in android by JSOUP?如何通过 JSOUP 从 android 中具有 class="title" 的 div 中获取所有文本?
【发布时间】:2015-06-07 08:21:31
【问题描述】:

我使用此代码但不是真的!为什么...?

String url = "http://example.com";
ProgressDialog mProgressDialog;

@Override
    protected Void doInBackground(Void... params) {
        try {
            // Connect to the web site
            Document document = Jsoup.connect(url).get();
            // Using Elements to get the Meta data
            Elements description = document
                    .select("div[class=title]");
            // Locate the content attribute
            desc = description.attr("content");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

如果我的html代码是

<div class="text-co">
<div class="title"><a href="">00</a>
                   <a href="">11</a>
                   <a href="">22</a>
</div>
</div>

<div class="text-co">
<div class="title"><a href="">33</a>
                   <a href="">44</a>
                   <a href="">55</a>
</div>
</div>

我想展示 00
11
22
33
44
55
jsoup 在我的 android 应用中,我应该怎么做

【问题讨论】:

  • 有什么问题?
  • 试试desc = description.text();

标签: android html jsoup gettext


【解决方案1】:

试试这个代码:

Elements anchors = document.select("div.title > a");
for(Element anchor : anchors) {
   Strig description = anchor.text();
   // ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 2016-03-18
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多