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 the absolute URL from the relative URL using Jsoup?

Many of the websites load various resources like images and CSS using the relative URLs. If you want to download these resources as well using Jsoup, you need to convert these relative URLs to the 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 a relative URL, it is converted to an absolute URL using the base URI and returned.



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

This example is a part of the Jsoup tutorial with examples.

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

About the author



My name is RahimV and I have over 16 years of experience in designing and developing Java applications. Over the years I have worked with many fortune 500 companies as an eCommerce Architect. My goal is to provide high quality but simple to understand Java tutorials and examples for free. If you like my website, follow me on Facebook and Twitter.

Add Comment

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

Online Shopping