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

因为想离线浏览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/ 下载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就直接生效了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值