Board logo

标题: 镜像网站的制作 [打印本页]

作者: happyfan    时间: 2010-12-11 22:49     标题: 镜像网站的制作


$ wget -mk -w 20
作者: happyfan    时间: 2010-12-11 22:54 ... -website-with-wget/

GNU's wget command line program for downloading is very popular, and not without reason. While you can use it simply to retrieve a single file from a server, it is much more powerful than that and offers many more features.

One of the more advanced features in wget is the mirror feature. This allows you to create a complete local copy of a website, including any stylesheets, supporting images and other support files. All the (internal) links will be followed and downloaded as well (and their resources), until you have a complete copy of the site on your local machine.

In its most basic form, you use the mirror functionality like so:
$ wget -m
There are several issues you might have with this approach, however.

First of all, it's not very useful for local browsing, as the links in the pages themselves still point to the real URLs and not your local downloads. What that means is that, if, say, you downloaded, the link on that page to would still point to's server and so would be a right pain if you're trying to browse your local copy of the site while being offline for some reason.

To fix this, you can use the -k option in conjunction with the mirror option:
$ wget -mk
Now, that link I talked about earlier will point to the relative page2.html. The same happens with all images, stylesheets and resources, so you should be able to now get an authentic offline browsing experience.

There's one other major issue I haven't covered here yet - bandwidth. Disregarding the bandwidth you'll be using on your connection to pull down a whole site, you're going to be putting some strain on the remote server. You should think about being kind and reduce the load on them (and you) especially if the site is small and bandwidth comes at a premium. Play nice.

One of the ways in which you can do this is to deliberately slow down the download by placing a delay between requests to the server.
$ wget -mk -w 20
This places a delay of 20 seconds between requests. Replace that number, and optionally you can add a suffix of m for minutes, h for hours, and d for ... yes, days, if you want to slow down the mirror even further.

Now if you want to make a backup of something, or download your favourite website for viewing when you're offline, you can do so with wget's mirror feature. To delve even further into this, check out wget's man page (man wget) where there are further options, such as random delays, setting a custom user agent, sending cookies to the site and lots more.
作者: happyfan    时间: 2012-2-26 15:13


wget -vE -rLnp -nH --tries=20 --timeout=40 --wait=5
wget -m
wget  -nc -B -F -nH --cut-dirs=3 -i index.html


-B 给指定的文件里的URLs增加路径前缀
-i : 下载所有在i参数后面指定的文件中列出的URLs.
-v : 显示信息
E : 强制以html 保存
-r : 递归, 就是抓取子目录的子目录
L : 相对路径
np : 不跳到父目录
-erobots=off :临时绕过robot.txt

ftp协议发布的文件的话就比较简单了,可以用 -r 参数 加通配符*来替代,完全可以实现递归下载!

PS:163的后来在加入了Robot Exclusion,而wget是遵循Robot Exclusion标准的,所以不修改wgetrc文件的话会下载到163的robot.txt,可以通过修改wgetrc里的robot开关来绕过robot或者通过”-erobots=off“参数来临时绕过robot.txt文件进行递归.

[ 本帖最后由 happyfan 于 2012-2-26 15:15 编辑 ]

欢迎光临 设计管理在线 ( Powered by Discuz! 6.0.0