Fetch complete web page using java code

前端 未结 3 2028
予麋鹿
予麋鹿 2021-01-06 03:33

I want to implement a java method which takes URL as input and stores the entire webpage including css, images, js (all related resources) on my disk. I have used Jsoup html

3条回答
  •  情书的邮戳
    2021-01-06 04:21

    Basically, you can do it with Jsoup:

     Document doc = Jsoup.connect("http://rabotalux.com.ua/vacancy/4f4f800c8bc1597dc6fc7aff").get();
             Elements links = doc.select("link");
             Elements scripts = doc.select("script");
            for (Element element : links) {
                  System.out.println(element.absUrl("href"));
            }
            for (Element element : scripts) {
                  System.out.println(element.absUrl("src"));
            }
    

    And so on with images and all related resources.

    BUT if your site creates some elements with javaScript, Jsoup will skip it, as it cant execute javaScript

提交回复
热议问题