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.

Example

Output

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.

Tags
Join 1000+ fellow learners! Enter your email address below: