利用wget获取NCL官网镜像

下载官网镜像:

nohup wget http://www.ncl.ucar.edu/ -np -c -m -k > wget.log 2>&1 &

解释下wget的选项
-m代表制作网站镜像
-np代表递归下载时不获取外部网站的链接,否则后果很严重.
-c代表支持断点续传
-k代表将下载下来的网页中的链接地址修改为本地地址

检查www.ncl.ucar.edu/文件夹

会发现有很多问题:

  • 文件夹中存在类似于Application.1这样的文件,实际上这也是一个html文件,但是浏览器不能识别后缀为.1的文件.
  • html文件和shtml文件中的链接有一些还没有修改为本地链接.

所以需要:

.1改名为.html:

#!/bin/bash
for filename in `find -name "*\.[1|9]$"
do
  rename "s/\.[1-9]$/\.html/" $filename
done

将文件内的链接改名:

#!/bin/bash
for filename in `find -name "*html"`
do
    number=0
    sed -i -e 's/https:\/\/www\.ncl\.ucar\.edu\//D:\/Websites\/www\.ncl\.ucar\.edu\//g' \
           -e 's/http:\/\/www\.ncl\.ucar\.edu\//D:\/Websites\/www\.ncl\.ucar\.edu\//g' \
           -e 's/NCL_to_Python\.[1-9]/NCL_to_Python\.html/g' \
           -e 's/Templates\.[1-9]/Templates\.html/g' \
           -e 's/Applications\.[1-9]/Applications\.html/g' \
           -e 's/util\.[1-9]/util\.html/g' \
           -e 's/Resources\.[1-9]/Resources\.html/g' \
           -e 's/Started\.[-9]/Started\.html/g' \
           -e 's/Data\.[1-9]/Data\.html/g' \
           -e 's/NCL_User_Guide\.[1-9]/NCL_User_Guide\.html/g' \
           -e 's/Manuals\.[1-9]/Manuals\.html/g' \
           -e 's/Cards\.[1-9]/Cards\.html/g' \
           -e 's/Tools\.[1-9]/Tools\.html/g' \
           -e 's/Download\.[1-9]/Download\.html/g' \
           -e 's/Support\.[1-9]/Support\.html/g' \
           -e 's/NCL_Graphics\.[1-9]/NCL_Graphics\.html/g' \
           -e 's/ALADIN\.[1-9]/ALADIN\.html/g' \
           -e 's/Scripts\.[1-9]/Scripts\.html/g' $filename
    let number=$number+1
    echo "$filename is Done   ($number/33125)"
done

将本地链接的绝对路径修改为相对路径:

你可能感兴趣的:(利用wget获取NCL官网镜像)