External Libraries

Jsoup get absolute URL example

Jsoup get absolute URL example shows how to get absolute URL from relative URL found in link href attribute or image src attribute using absURL method of element class.

How to get absolute URL from relative URL using Jsoup?

Many of the websites load various resources like images and css using relative URLs. If you want to download these resources as well using Jsoup, you need to convert these relative URLs to absolute URLs.

Jsoup element class provides absUrl method which converts relative URLs to absolute URL using base URI.

If the URL is already an absolute URL, it is returned as is. If it is relative URL, it is converted to absolute URL using base URI and returned.



You can also use attr method with “abs:”¬†prefix with attribute name to get the absolute URL instead of absUrl method as given below.

Please let us know your views in the comments section below.

Want to learn quickly?
Try one of the many quizzes. I promise you will not be disappointed.


About the author



rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.

Add Comment

Your email address will not be published. Required fields are marked *