Wget is an excellent HTTP/FTP download tool, which is powerful and available on almost all UNIX systems. However, using it to dump modern websites has a problem: CSS files are not supported, and it will not automatically download or relink the images specified in CSS. The most common consequence of this problem is that dump-down websites cannot see background images. The script described in this article is mainly used to solve this defect.
Here is a brief introduction to the details of this script:
- Row 3 is used to set the address of the website to be downloaded.
- Line 2 is used to convert the file name to a Windows-compatible format. Windows has more stringent file name format requirements than Unix. It can be specified as windows compatible with Unix systems. In general, this feature of wget is a little weaker, and there is no way to deal with more demanding systems.
- The 13th row is used to skip robots.txt. Many of the cssjs files on the website are defined as Spider inaccessible in robots.txt.
- Lines 15th and 16 are used to ignore some directories and files. Because there is no robots.txt restriction, wget may access unnecessary things. Restrictions can be made based on the actual situation.
- 19th ~ Download the linked files in CSS in 24 rows.
- 26th ~ Line 29 fixes the link in CSS.
The content of this script is as follows:
- #! /Bin/sh
- ADDR = "http://www.EXAMPLE.com /"
- Server =$ {ADDR # http ://}
- Server =$ {server % /*}
- Wget/
- -- HTML-extension/
- -- Restrict-file-names = Windows/
- -- Convert-links/
- -- Page-requisites/
- -- Execute robots = off/
- -- Mirror/
- -- Exclude-directories/comment/reply/,/aggregator/,/user //
- -- Reject "aggregator *"/
- "$ ADDR"
- Find $ server-type F-name "*. CSS"-exec cat {}/; |
- Grep-O 'url (/[^)] *) '|
- Sort |
- Uniq |
- Sed's/^ URL (/(. */) $/http: // '$ Server'/1/' |
- Wget -- mirror -- page-requisites-I-
- For I in 'Find $ server-type F-name "*. CSS" '; do
- Prefix = "$ (echo $ I | SED's/[^ //] * // G; S // $ //; s ////.. //// G ')"
- Sed-I's/URL (// URL ('$ prefix'/G' $ I
- Done