how to download offlice copy of website using wget in linux? And ignore specific pages
- User
how to download offlice copy of website using wget in linux? And ignore specific pages
- Assistant
To download an offline copy of a website using
wgeton Linux and ignore (exclude) specific pages, you can use various options provided bywget.Basic Command to Download a Website Offline
bashwget --mirror --convert-links --adjust-extension --page-requisites --no-parent URLExplanation:
--mirror: Enables options suitable for mirroring (recursive download, timestamping, infinite recursion depth, etc.)--convert-links: Convert the links in the downloaded files to make them suitable for offline viewing.--adjust-extension: Save files with the appropriate extensions (e.g.,.html)--page-requisites: Download all assets (images, CSS, JS) required to display the pages properly.--no-parent: Do not ascend to the parent directory; limits the download to the specified directory and below.
Ignoring Specific Pages
wgetdoes not have a direct "exclude URL" option, but you can filter URLs by:- Using
--rejectto skip files by extension or pattern. - Using
--reject-regexto reject URLs matching a regular expression. - Using
--exclude-directoriesto avoid specific subdirectories.
For ignoring particular pages, use
--reject-regex.Example:
bashwget --mirror --convert-links --adjust-extension --page-requisites --no-parent --reject-regex 'page1.html|ignore-this' URL- This skips URLs containing
page1.htmlorignore-thisin their path.
Full Example
Suppose you want to download
https://example.combut want to ignore pageshttps://example.com/ignore-me.htmland any URL containing/secret/:bashwget --mirror --convert-links --adjust-extension --page-requisites --no-parent --reject-regex 'ignore-me.html|/secret/' https://example.com