0

I want to extract/parse the body of HTML pages. To do so, I use the Jsoup API: https://jsoup.org/.

However, I also want to extract the CSS, but how to do it when it is in a different folder ?

My code so far is writing the code of the page in a tempFile, so I now need to get the CSS of this page to apply it in this file:

 public File parseHtml(String url) throws IOException {

    Document doc = Jsoup.connect(url).get();
    Element body = doc.body();
    File tempFile = File.createTempFile(suffix, prefix);
    BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
    writer.write(body.outerHtml());
    writer.close();
    return tempFile;
}

1 Answer 1

1

Grab the individual url of the CSS File out of the script-Element.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply! However, the issue is that I cannot get that url programmatically from the first url of my website. I can only get the href but therefore, I cannot use the file.
Hm.. you can get the text of the css file into a string, create a new file and push the string into this file. now you should have a clone. this clone is on your control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.