I have translated the PHP Simple HTML DOM query:
$article->find('td[id$=tdDescription] div a', 1)->plaintext;
to the jsoup query:
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?
With XPath expressions it is able to select the elements within the HTML using Jsoup as HTML parser.
A HTML element consists of a tag name, attributes, and child nodes (including text nodes and other elements). From an Element, you can extract data, traverse the node graph, and manipulate the HTML.
jsoup can parse HTML files, input streams, URLs, or even strings. It eases data extraction from HTML by offering Document Object Model (DOM) traversal methods and CSS and jQuery-like selectors. jsoup can manipulate the content: the HTML element itself, its attributes, or its text.
Use Elements#get()
instead. This allows accessing elements by index.
resultRow.select("td[id$=tdDescription] > div > a").get(1).text();
Use td[id$=tdDescription] > div > a:eq(2)
selector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With