我是android和Jsoup场景的新手,转换表时遇到一个小问题。 使用例如此链接 http://mywheels.ie/car-history-check/free-car-check-results/?VRN=00C31865 如何解析表格并在日志中显示右侧的FIAT,RED,PETROL元素?提前谢谢
答案 0 :(得分: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);
}
}
}