Skip to content Skip to sidebar Skip to footer

Extracting Href From A Class Within Other Div/id Classes With Jsoup

Hello I am trying to extract the first href from within the 'title' class from the following source (the source is only part of the whole page however I am using the entire page):

Solution 1:

The CSS selector div.title, returns a <div class="title">, not a link as you seem to think. If you want an <a class="title"> then you should use the a.title selector.

Elementlink= document.select("a.title").first();
Stringhref= link.absUrl("href");
// ...

Or if an <a class="title"> can appear elsewhere in the document outside a <div class="title"> before that point, then you need the following more specific selector:

Elementlink= document.select("div.title a.title").first();
Stringhref= link.absUrl("href");
// ...

This will return the first <a class="title"> which is a child of <div class="title">.

Post a Comment for "Extracting Href From A Class Within Other Div/id Classes With Jsoup"