Jsoup从表中获取表中的数据

这并不简单。 我正在解析一个页面( http://www.catedralaltapatagonia.com/invierno/partediario.php?default_tab=0 )我需要在其他表中的表中满足的数据,但我无法访问,因为我收到关于无效索引的所有错误指数

我需要这个价值观

我需要的细胞

这个单元格位于tr内部的td内部,在表格内部,此表格位于另一个表格内。 每列单元格都在div id“meteo_info”中,并且在每个td内部都有相同的名称div id。

我试过这种方式没有成功

Elements base1=document.select("div#pd_foto_fondo"); Elements base2 = base1.select("table"); Elements base3 = base2.select("tr"); Elements base4 = base3.select("table"); Elements base5 = base4.select("tr"); Elements base6 = base5.select("td"); Element base7 =base6.get(0); Element div1 = base7.getElementById("meteo_info"); Elements tables1 = div1.getElementsByTag("table"); Element table1 = tables1.get(0); String text2 = table1.getElementsByTag("tr").get(3).getElementsByTag("td").get(2).text(); 

我在Asyntask doInBackground中使用此代码

首先,在应用程序中下载网页时,请更改“ USER AGENT字段以匹配您在计算机上使用的浏览器。 我将保证您在应用中使用相同的标签获得完全相同的页面。
我使用FF,但如果你使用另一个浏览器它应该几乎相同 –
打开开发人员工具(在FF中为F12),选择检查器并选择元素选择器(FF – 最左边的工具)。 之后选择你想要的其中一个元素,让我们来看看SECTOR BASE的SensaciónTérmica。 浏览器将突出显示包含该元素的代码。
将鼠标放在highligthed代码上,右键单击它并选择Copy unique selector
然后你可以使用这段代码来获取元素 –

 Elements e = doc.select("#pd_foto_fondo > table:nth-child(5) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > div:nth-child(1) > div:nth-child(3) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(3)"); 

你可以得到价值

 e.text(); 

现在,为你需要的所有元素做这些,你会发现一个模式 – 有三个表(SECTOR BASE,SECTOR INTERMEDIO,SECTOR SUPERIOR),他们的id从最后到第7位(不容易看到,太长了……) –

 #pd_foto_fondo > table:nth-child(5) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > div:nth-child(1) > div:nth-child(3) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(3) #pd_foto_fondo > table:nth-child(5) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > div:nth-child(1) > div:nth-child(3) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(3) #pd_foto_fondo > table:nth-child(5) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > div:nth-child(1) > div:nth-child(3) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(3) 

而且,每一行都有不同的id,这次是从最后开始的第二行。 SensaciónTérmica是

 #pd_foto_fondo > table:nth-child(5) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > div:nth-child(1) > div:nth-child(3) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(3) 

和Viento是

 #pd_foto_fondo > table:nth-child(5) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > div:nth-child(1) > div:nth-child(3) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(3) 

(注意最后两行的4和5)。
您可以使用两个嵌套for循环遍历这些选择器并获取所需的所有信息。