Java JSOUP解析两个表

Java JSOUP解析两个表,java,android,parsing,jsoup,Java,Android,Parsing,Jsoup,我已经解析了第一个表,但我不知道如何解析第二个表 阿里维 Ultimo aggiornamento:17/04/2014 10:12 公司 N 普罗旺尼亚 日程安排 史提马托 斯塔托 瑞安航空 03071 朗德拉·斯坦斯特德 17/04/2014 12:40 17/04/2014 12:32 在orario 瑞安航空 04075 考纳斯 17/04/2014 16:10 17/04/2014 16:10 在orario 瑞安航空 07316 都柏林诺 17/04/2014 20:45 17/0

我已经解析了第一个表,但我不知道如何解析第二个表


阿里维
Ultimo aggiornamento:17/04/2014 10:12
公司
N
普罗旺尼亚
日程安排
史提马托
斯塔托
瑞安航空
03071
朗德拉·斯坦斯特德
17/04/2014 12:40
17/04/2014 12:32

在orario 瑞安航空 04075 考纳斯 17/04/2014 16:10 17/04/2014 16:10
在orario 瑞安航空 07316 都柏林诺 17/04/2014 20:45 17/04/2014 20:45
在orario 帕坦泽 Ultimo aggiornamento:17/04/2014 10:12 公司 N 脱硝脲 日程安排 史提马托 斯塔托 瑞安航空 03074 朗德拉·斯坦斯特德 17/04/2014 13:05 17/04/2014 13:05
在orario 瑞安航空 04076 考纳斯 17/04/2014 16:35 17/04/2014 16:35
在orario 瑞安航空 07317 都柏林诺 17/04/2014 21:10 17/04/2014 21:10
在orario
第一个表解析为:

org.jsoup.nodes.Document doc = Jsoup.connect("http://site.eu").timeout(7*1000).get();

org.jsoup.nodes.Element tabella = doc.getElementsByClass("tabella-voli").first();
Iterator<org.jsoup.nodes.Element> iterator = tabella.select("td").iterator();

while(iterator.hasNext()){

org.jsoup.nodes.Document doc=jsoup.connect(“http://site.eu)超时(7*1000).get();
org.jsoup.nodes.Element tabella=doc.getElementsByClass(“tabella voli”).first();
迭代器迭代器=tabella.select(“td”).Iterator();
while(iterator.hasNext()){

你能帮我只解析第二个表吗?我只需要td元素。

你可以直接在一个元素类的invoque“first()”上实例化它。 然后,您将能够使用“get(int)”方法解析所需的表:


然后,您将得到一个元素列表,其中包含第二个表中的所有“td”。

如果您想在“td”列表上使用迭代器,那么您只需执行与之前相同的操作:“迭代器迭代器=tdElements.Iterator();”,即使我不明白为什么您绝对需要它:迭代集合的方法有很多种…迭代器很好,为什么我使用while()来到达集合的末尾..其他解决方案?您可以使用“for(Element tempElement:elements)”甚至“for(int index=0;indexorg.jsoup.nodes.doc=jsoup.connect(*1000).get();Elements tables=currentServerPage.getElementsByClass(“tabella voli”);Element secondTable=tables.get(1);Elements tdElements=currentServerPage.getElementsByTag(“td”);for(Element tempElement:tdElements){thread++;System.out.println(tdElements);is error“System.out.println(tdElements)”不应该改为“System.out.println(templement)”吗?
Elements tables = currentServerPage.getElementsByClass("tabella-voli");
Element secondTable = tables.get(1);
Elements tdElements = currentServerPage.getElementsByTag("td");