Use wget to capture Website webpages, including CSS background images

Source: Internet
Author: User
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:

  1. #! /Bin/sh
  2. ADDR = " /"
  3. Server =$ {ADDR # http ://}
  4. Server =$ {server % /*}
  5. Wget/
  6. -- HTML-extension/
  7. -- Restrict-file-names = Windows/
  8. -- Convert-links/
  9. -- Page-requisites/
  10. -- Execute robots = off/
  11. -- Mirror/
  12. -- Exclude-directories/comment/reply/,/aggregator/,/user //
  13. -- Reject "aggregator *"/
  14. "$ ADDR"
  15. Find $ server-type F-name "*. CSS"-exec cat {}/; |
  16. Grep-O 'url (/[^)] *) '|
  17. Sort |
  18. Uniq |
  19. Sed's/^ URL (/(. */) $/http: // '$ Server'/1/' |
  20. Wget -- mirror -- page-requisites-I-
  21. For I in 'Find $ server-type F-name "*. CSS" '; do
  22. Prefix = "$ (echo $ I | SED's/[^ //] * // G; S // $ //; s ////.. //// G ')"
  23. Sed-I's/URL (// URL ('$ prefix'/G' $ I
  24. Done
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.