jsoup第二个元素,而不是第一个()
问题描述:
我翻译了PHP简单的HTML DOM查询:jsoup第二个元素,而不是第一个()
$article->find('td[id$=tdDescription] div a', 1)->plaintext;
到jsoup查询:
resultRow.select("td[id$=tdDescription] > div > a").first().text());
,你可以看到我访问PHP中的第二个(1)结果,当前在jsoup中使用.first()我正在访问第一个结果(0),但我也想访问第二个结果(1),我该怎么做?
答
改为使用Elements#get()
。这允许按索引访问元素。
resultRow.select("td[id$=tdDescription] > div > a").get(1).text());
答
使用td[id$=tdDescription] > div > a:eq(2)
选择。
这帮了我一大堆。谢谢! – jasonflaherty 2012-12-04 06:51:19