Search code examples
javahtml-parsinghtmlunit

Get resources of a page using HtmlUnit


How do I get the "absolute URL" and the "File" of all resources that a page loads?

When I have a HtmlPage object in the variable page, page.save(new File(path)); saves the resources. If I save the resources like this I just have the files but not the corresponding URLs.


Solution

  • Solved it with the help of: https://stackoverflow.com/a/31261340/3634099

    @Override
    public WebResponse getResponse(WebRequest request) throws IOException {
     WebResponse response = super.getResponse(request);
     request.getUrl()
     request.getUrl().getPath();
     request.getUrl().getFile();
     return response;
    }