我是 android 和 Jsoup 场景的新手,在转换表格时遇到了一个小问题。使用例如此链接 http://mywheels.ie/car-history-check/free-car-check-results/?VRN=00C31865 如何解析表格并显示右侧 FIAT、RED、汽油在日志中?先感谢您
问问题
1568 次
1 回答
1
import java.util.Iterator;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class JsoupTest1 {
public static void main(String[] args) {
Document doc = Jsoup.parse("<table><tr class='eventTableRow'><td id='1' class='class1'>value1</td><td id='2' class='class2'>value2</td><td id='3' class='class3'>value3</td></tr></table>");
Elements row = doc.select(".eventTableRow td");
Iterator<Element> iterator = row.listIterator();
while(iterator.hasNext())
{
Element element = iterator.next();
String id = element.attr("id");
String classes = element.attr("class");
String value = element.text();
System.out.println("Id : " + id + ", classes : " + classes+ ", value : " + value);
}
}
}
于 2013-10-12T21:18:38.433 回答