How to Download a Single Page with Wget and Assets?
When you need to save a web page for offline viewing, downloading
just the raw HTML file usually results in a broken layout missing its
styles, scripts, and images. This article explains how to configure
wget to automatically fetch an HTML page along with only
the specific page requisites—like CSS, JavaScript, and images—needed to
display that single page correctly. We will cover the exact command-line
flags required, how to convert links for local viewing, and how to avoid
accidentally downloading the entire website.
The Core Command
To download a single HTML page and all the assets required to render it properly offline, use the following combination of flags:
wget -p -k -E https://example.com/page.htmlBreakdown of the Flags
Using wget without any options will only download the
isolated HTML file. To get the assets, each flag in the command plays a
specific role:
-p(or--page-requisites): This tellswgetto download all the files that are necessary to properly display the given HTML page. This includes inline images, stylesheets (CSS), sounds, and scripts.-k(or--convert-links): After the download is complete, this option converts the links in the document to make them suitable for local viewing. It changes remote URLs (likehttps://example.com/style.css) to relative paths pointing to your freshly downloaded local files.-E(or--adjust-extension): If the page or assets do not have a standard extension (for example, a page ending in.phpor a dynamic URL), this flag forceswgetto append.htmlor the appropriate extension to the local file name, ensuring your browser opens it correctly.
Preventing Crawler Creep
By default, using -p will grab assets even if they are
hosted on a different domain (like a font hosted on Google Fonts or a
script on a CDN). However, it will not start spidering through
the rest of the website’s links.
If you want to be absolutely certain that wget does not
follow links to other pages or move up to parent directories, you can
add the strict non-recursive flag:
wget -p -k -E -level=0 https://example.com/page.htmlUsing this command creates a self-contained local folder structure containing the target HTML page and a folder for its assets, allowing you to open the page in any browser completely offline with all visual elements intact.