您的位置:首页 > 运维架构 > 网站架构

用wget递归下载网站 离线浏览

2016-02-20 21:10 513 查看
因为想离线浏览www.tutorialspoint.com

—An Indian Website

因为Teleport收费

所以只好使用免费的自由软件

帮助信息

$ wget --help


可以显示详细的

命令

$ sudo wget -r -H -Dtutorialspoint.com -np -k -p www.tutorialspoint.com


选项

-r, –recursive specify recursive download 默认5级目录 可通过 -l number改动

-H, –span-hosts go to foreign hosts when recursive

不加-H选项时,不会识别
<a href="/apex/index.htm" title="Learn Apex Programming">Learn Apex</a>
这样的超链接。测试可以接受
<link href=
开头的超链接,很confusing,下面是来自gnu网站的说法

wget gnu manual ftp://ftp.gnu.org/old-gnu/Manuals/wget-1.8.1/html_chapter/wget_4.html

-H span to any host

-D limit spanning to certain domain
sudo wget -rH -Dserver.com http://www.server.com/[/code] 下载
www.server.com
,同时允许下载
images.server.com


你也可以
-Ddomain1.com,domain2.com --exclude-domains sunsite.domain1.com


-k, –convert-links make links in downloaded HTML or CSS point to local files 将下载的html页面中链接转换为指向本地文件的链接

–convert-file-only convert the file part of the URLs only(usual only known as the basename)

-p, –page-requisites get all images, etc. needed to display HTML page 下载所有图片等页面显示元素

–strict-comments turn on strict (SGML) handling of HTML comments

-np, –no-parent don’t ascend to the parent directory不追溯至父级

-nc, –no-clobber skip downloads that would download to existing files thus overwriting them 断点续传

-A, –accept=LIST comma-separated list of accepted extensions

后续问题

下下来后,发现没有更正全部的超链接。

比如要访问 file:///Users/username/Documents/www.tutorialspoint.com/index.html里,仍然包含了href=”www.tutorialspoint.com/apex/index.htm”

所以构思把网页放到本地服务器localhost上,离线时修改dns解析到下载的网页。

修改 /etc/hosts 文件

127.0.0.1   example.com             alias.example.com
127.0.0.1   www.tutorialspoint.com  tutorialspoint.com


添加最后一行即可

如果是Mac 根据hosts(5) manual page
/etc/hosts
文件是由
mDNSResponder
使用。重置DNS缓存方法为:

sudo dscacheutil -flushcache


我的OS X 10.10发现修改完hosts就直接生效了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: