用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 文件
添加最后一行即可
如果是Mac 根據hosts(5) manual page /etc/hosts文件是由mDNSResponder使用。重置DNS緩存方法為:
sudo dscacheutil -flushcache
我的OS X 10.10發現修改完hosts就直接生效了
總結
以上是生活随笔為你收集整理的用wget递归下载网站 离线浏览的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 集群启动命令
- 下一篇: 安装gnome3桌面环境_在Linux上