java jsoup 第二个元素而不是 first()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6236972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:57:59  来源:igfitidea点击:

jsoup second element instead of first()

javaphpjsoupsimple-html-dom

提问by Dominik

I have translated the PHP Simple HTML DOMquery:

我已经翻译了PHP Simple HTML DOM查询:

$article->find('td[id$=tdDescription] div a', 1)->plaintext;

to the jsoupquery:

jsoup查询:

resultRow.select("td[id$=tdDescription] > div > a").first().text());

as you can see I am acessing the second (1) result in PHP, currently in jsoup with the .first() I am accessing the first result (0) but I would also like to access the second result (1), how would I do that?

如您所见,我正在访问 PHP 中的第二个 (1) 结果,目前在带有 .first() 的 jsoup 我正在访问第一个结果 (0) 但我也想访问第二个结果 (1),怎么会我这样做?

回答by BalusC

Use Elements#get()instead. This allows accessing elements by index.

使用Elements#get()来代替。这允许按索引访问元素。

resultRow.select("td[id$=tdDescription] > div > a").get(1).text();

回答by Afroz Shaikh

Use td[id$=tdDescription] > div > a:eq(2)selector.

使用td[id$=tdDescription] > div > a:eq(2)选择器。