Skip to content
Advertisement

Get n-th child Element with Jsoup

For example a web site has a code like this:

JavaScript

and I want to get the “second” div text with “Jsoup” and it has no attribute or class.

Advertisement

Answer

There are few ways to to it. select returns Elements instance which extends ArrayList<Element> so you can select all child divs and pick one at specified index (starting from 0) like

JavaScript

Output:

JavaScript

You can also use :eq(n) selector which (from official tutorial)

find elements whose sibling index is equal to n; e.g. form input:eq(1)

like

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement