Vote count:
0
I'm trying to parse a table, save its contents and textview as table. It works perfectly for some urls, but not for this one (http://ift.tt/1pM3W34) . Some rows aren't printed correctly. My code's jsoup part:
try {
Document doc = Jsoup.connect(url).get();
db.deleteAllBandeco2();
Elements tableElements = doc.select("table");
Elements tableRowElements = tableElements
.select(":not(thead) tr"); //para ignorar o título
for (int i = 1; i < tableRowElements.size(); i++) {
Element row = tableRowElements.get(i);
System.out.println("row");
Elements rowItems = row.select("td");
for (int j = 0; j < rowItems.size(); j++) {
boolean isPreFound = false;
Elements rowSubItems = rowItems.get(j).select("pre");
Elements rowSubItemsByH5 = rowItems.get(j).select("h5");
Elements rowSubItemsByP = rowItems.get(j).select("p");
Elements rowSubItemsByB = rowItems.get(j).select("b");
StringBuilder coulmn = new StringBuilder();
for (int k = 0; k < rowSubItems.size(); k++) {
isPreFound = true;
String text = rowSubItems.get(k).text();
if (text.equals("SEGUNDA-FEIRA")
|| text.equals("TERÇA-FEIRA")
|| text.equals("QUARTA-FEIRA")
|| text.equals("QUINTA-FEIRA")
|| text.equals("SEXTA-FEIRA")
|| text.equals("SÁBADO")
|| text.equals("DOMINGO")) {// Creates titles
coulmn.append("<b>" + text + "</b>" + "<br />");
} else if (text.trim().length() > 0) {
coulmn.append("<small>" + text + "</small>"
+ "<br />");
}
System.out.println(rowSubItems.get(k).text() +
"\n\n");
}
for (int m = 0; m < rowSubItemsByH5.size(); m++) {
String text = rowSubItemsByH5.get(m).text();
if (text.trim().length() > 0) {
coulmn.append("<b>" + text + "</b>" + "<br />");
}
}
for (int l = 0; l < rowSubItemsByP.size(); l++) {
String text = rowSubItemsByP.get(l).text();
if (text.trim().length() > 0) {
coulmn.append("<small>" + text + "</small>"
+ "<br />");
}
}
if (isPreFound == false) {
for (int l = 0; l < rowSubItemsByB.size(); l++) {
String text = rowSubItemsByB.get(l).text();
if (text.trim().length() > 0) {
coulmn.append("<b>" + text + "</b>"
+ "<br />");
}
}
}
if (coulmn.length() > 0) {
db.addBandeco2(coulmn.toString());
}
}
}
termVar = "success";
} catch (IOException e) {
Log.e("", "" + e.toString());
termVar = "error";
}
return termVar;
Sorry for the long post. I would appreciate any kind of help! Thanks!!
asked 19 secs ago
Aucun commentaire:
Enregistrer un commentaire