Search code examples
javahtmlcssjsoup

How to get css absolute path from webpage url in Java?


My aim is to enter the url of a website, and from this url, get the css of this website. However, I do not know how to get the absolute url of the css from the website url. I tried to workaround by getting the relative path using Jsoup (https://jsoup.org/) but I did not succeed.

Anyone has an idea on how to get the absolute path of css or any other idea on how I could retrieve it?


Solution

  • There's an example in the documentation : https://jsoup.org/cookbook/extracting-data/working-with-urls

    String absHref = link.attr("abs:href"); // "http://jsoup.org/"
    

    If you want this for CSS you could pass the absHref into an URI object an take the hostname and prepend with whatever relative URL is available for the stylesheet(s).