I have many locally-saved .HTML files that have links to remote images. I am looking for a command-line utility that would batch convert these "HTML Only" files to "Webpage, Complete" files - i.e. download the remote images for each local HTML file, and save the HTML file with the same name it had before, but with the image links now pointing to the local copies of the images, stored in a sidecar folder with the same name as the HTML file. I have looked at many different tools but haven't found what I'm looking for yet - maybe somebody can tip me off to a tool I've missed.

Edit: I think I've found a way to getting something close to what I want. I can start up an http server to serve up files in a local folder as follows:

python -m http.server 8000

Then I can use httrack to mirror a page (with remote images) as follows:

httrack http://localhost:8000/localpagetomirror.html -n

I think I could also use wget in this way but I haven't figured out the syntax yet.

If anybody has a better method or tool I'm all ears.

  • 1
    Try Chrome in headless mode: google-chrome --disable-gpu --headless $URL --print-to-pdf && mv output.pdf $OUTFILE This would create a complete pdf from each web page. I think you can adapt the command to download the pages with html code, images, JS- and CSS codefiles into their own respective directories (1 dir per url). Maybe try Google puppeteer.
    – knb
    Sep 29, 2023 at 11:47
  • Thank you knb. I know headless chrome will be able to fetch images that httrack or wget won't be able to fetch. For some reason Headless Chrome, Puppeteer, Selenium seem to be focused on getting PDFs or screenshots, with no provision for creating a local mirror of the page. I found Pappet (github.com/patrickschur/pappet) which will create an mhtml file (not exactly what I want but closer), but on first try i couldn't get it to work, will try again, this time running a local HTTP server as described above.
    – Jim
    Oct 1, 2023 at 16:17


Your Answer

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

Browse other questions tagged or ask your own question.