Android解析html表格

Android解析html表格

本文介绍了Android解析html表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < table width =75%border =2 id =INVALSI> 
< tbody>
< tr>
< td width =5%align =center>< strong> UNITA'< br> SINTATTICA
< / strong>< / td>
< td width =45%align =center>< strong> ANALISI< br> LOGICA
< / strong>< / td>
< td width =50%align =center>< strong> RISPONDE< br> ALLA
DOMANDA:
< / strong>< / td>
< / tr>
< tr>
< td align =leftstyle =padding:4px 4px 2px 6px;>< strong> ciao< / strong>< / td>
< td align =leftstyle =padding:4px 4px 2px 6px;>< strong> complemento
vocativo(o esclamativo)< / strong>< / td>
< td align =leftstyle =padding:4px 4px 2px 6px;>< strong> CI
SI INDIRIZZA QUALCUNO?< / strong>< br>< / TD>
< / tr>
< / tbody>
< / table>

如何选择strong并将其解析为listview?

解决方案

您可以使用Jsoup HTML解析器来获取所需的数据。 >第1步。从下载jsoup.jar。



第2步。将它添加到项目的libs文件夹中。

第3步。提取所需的数据

  ArrayList< String> list = new ArrayList< String>(); 
Document doc = Jsoup.parse(your html);
元素元素= doc.select(strong);
for(int i = 0; i< elements.size(); i ++)
{

list.add(elements.get(i).text()。toString ());


$ / code $ / pre
$ b $ p最后

  ArrayAdapter< String> adapter = new ArrayAdapter< String>(ActivityName.this,android.R.layout.simple_list_item_1,list); 
listview.setAdapter(adapter);


I need to parse data table look like this:

<table width="75%" border="2" id="INVALSI">
    <tbody>
        <tr>
            <td width="5%" align="center"><strong>UNITA'<br>SINTATTICA
            </strong></td>
            <td width="45%" align="center"><strong>ANALISI<br>LOGICA
            </strong></td>
            <td width="50%" align="center"><strong>RISPONDE<br>ALLA
                    DOMANDA:
            </strong></td>
        </tr>
        <tr>
            <td align="left" style="padding: 4px 4px 2px 6px;"><strong>ciao</strong></td>
            <td align="left" style="padding: 4px 4px 2px 6px;"><strong>complemento
                    vocativo (o esclamativo)</strong></td>
            <td align="left" style="padding: 4px 4px 2px 6px;"><strong>CI
                    SI INDIRIZZA A QUALCUNO?</strong><br></td>
        </tr>
    </tbody>
</table>

How can I select the "strong" and parse it into a listview?

解决方案

You ca use Jsoup HTML parser to get the required data

Step 1. Download the jsoup.jar from http://jsoup.org/download

Step 2. Add it to the libs folder of your project.

Step 3. Extract Data required

    ArrayList<String> list = new ArrayList<String>();
    Document doc = Jsoup.parse("your html");
    Elements elements = doc.select("strong");
    for(int i=0;i<elements.size();i++)
    {

        list.add(elements.get(i).text().toString());

    }

Finally

ArrayAdapter<String> adapter = new ArrayAdapter<String>(ActivityName.this,android.R.layout.simple_list_item_1,list);
listview.setAdapter(adapter);

这篇关于Android解析html表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 03:51