Skip to content

/commands/wget/wget-mirror-website

wget --mirror --convert-links --page-requisites: download a website for offline use

The commands on this page have not been executed by our verification runner yet.updated
tool
wget
versions
GNU Wget 1.x
os
linux, macos, windows

wget --mirror --page-requisites --convert-links --adjust-extension --no-parent https://example.org/docs/ downloads every page under /docs/ together with the images, stylesheets and scripts they use, and rewrites the links so the copy works offline from your disk. --mirror turns on recursion with infinite depth and timestamping, --no-parent keeps wget from climbing above the start directory, and the files are saved under a folder named after the host.

Command

bash
wget --mirror --page-requisites --convert-links --adjust-extension --no-parent \
     --wait=1 --random-wait \
     https://example.org/docs/

Short form: wget -m -p -k -E -np -w 1 https://example.org/docs/. Open example.org/docs/index.html in a browser afterwards.

Options

OptionEffect
-m, --mirrorSame as -r -N -l inf --no-remove-listing: recursive, timestamps, unlimited depth
-p, --page-requisitesAlso download images, CSS and scripts needed to display each page
-k, --convert-linksAfter the download, rewrite links to point to the local copies
-E, --adjust-extensionSave HTML and CSS with .html/.css extensions so they open locally
-np, --no-parentNever go to the parent directory of the start URL
-l N, --level=NLimit the recursion depth (default 5 with -r, unlimited with -m)
-w N, --wait=N / --random-waitPause between requests to reduce load on the server
-H, --span-hosts with -D domainsFollow links to other hosts, limited to the listed domains
-R / -AReject or accept file name patterns, for example -R "*.zip,*.iso"
-nH, --cut-dirs=NDo not create the host directory, drop N leading directories

Things to know

  • wget follows robots.txt during recursive downloads. -e robots=off disables that; use it only on sites you are allowed to copy.
  • Pages built in the browser by JavaScript are saved as their initial HTML; wget does not run scripts, so such sites often come out empty.
  • Rerunning the same --mirror command updates the copy: thanks to timestamping (-N) only files that changed on the server are downloaded again.
  • Images on a CDN host are skipped unless you add -H -D cdn.example.org,example.org.
  • Logged-in areas need cookies: --load-cookies cookies.txt with a cookie file exported from the browser.

Sources