0

I have problem with parsing html. I wanted to retrieve all the tables from this website http://www.zmksstalowawola.pl/taranhtml/linie_r.htm and get second cell of each received table. Here is my code that I wrote to get this effect. To check if code is working I added TextView to display received cells.

Document document = Jsoup.connect("http://www.zmksstalowawola.pl/taranhtml/linie_r.htm").get();
TextView tv = (TextView)findViewById(R.id.htmlView);
ArrayList<String> arrayList  = new ArrayList<String>();
Elements tables = document.select("table");
for (Element table : tables) {
        String rowData = table.select("td").get(1).toString();
        arrayList.add(rowData);
        tv.setText(rowData);
}

The problem is that the TextView does not display any text from cell (only text that I've write in xml activity file). I was looking for answers in many websites tutorials and it should working. I have set INTERNET permission so it's not the point. I also have all the required libraries. If anyone knows why it does not work, I would be grateful for your help. Sorry for my poor language

4

1 回答 1

0

toString()这种方式可能不适合你。如果您确定document其中包含所需的 HTML,则应使用text(),如下所示:

Document document = Jsoup.connect("http://www.zmksstalowawola.pl/taranhtml/linie_r.htm").get();
TextView tv = (TextView)findViewById(R.id.htmlView);
ArrayList<String> arrayList  = new ArrayList<String>();
Elements tables = document.select("table");
for (Element table : tables) {
    String rowData = table.select("td").get(1).text();  //text() instead of toString()
    arrayList.add(rowData);
    tv.setText(rowData);
}
于 2012-08-11T11:16:53.457 回答