Jieke Wei
Jieke Wei

Reputation: 183

Jsoup - get url from element

I have an element link.(link is <li class="books"><a href="catagory.php?cat=books">Books</a></li>)

I am trying to parse the hred from this element using String url = link.attr("href"); It gives an empty string. Why?

(abs:href is also tried. Not working)

Upvotes: 0

Views: 52

Answers (1)

johnII
johnII

Reputation: 1433

You should drill down to a specific element and then use the selector.

link.select("li a").attr("href")

In this case we need the attr of "a" element and not the "li"

Upvotes: 1

Related Questions