linux下可以用wget下载整个网站,而且网站链接中包含utf-8编码的中文也能正确处理。

简要方法记录如下:
wget --restrict-file-name=ascii -m -c -nv -np -k -E -p -R=exe,zip http://www.xxx.com
参数释义如下:
--restrict-file-name=ascii ,将文件名保存为ASCII格式。这样能避免utf-8文件名带来的麻烦(注:1.12版才支持ascii参数值)
-m 整站下载,mirror的缩写,是-N -r -l inf --no-remove-listing 这几个参数的快捷方式,具体详阅各自的说明
-c 续传
-nv 不显示详细的下载详情
-np don’t ascend to the parent directory.即下载的Web页面不越过后面指定的 http://www.xxx.com的范围。当然,如果你指定的是 http://www.xxx.com/aaa,则所有的web页面都要在 http://www.xxx.com/aaa下
-k 下载完成后,将页面文件中的链接转换为本地链接,便于离线浏览和制作chm等
-E 保存html/css文件时,使用合适的文件后缀。例如,在某些网站有些文件是服务器端动态生成的,虽然是css文件,但后缀并不是css,-E选项可以调整之
-p -np对页面文件做了限制,如果不加-p,则html所需的媒体文件也会受限于-np,-p则会下载html/css文件所需的所有媒体文件(图片、音频、视频等)
-R 拒绝下载的文件后缀列表,逗号分隔
至于下载到的文件的文件名变为了形如%A7这样百分号加16进制数字的形式,可以用个python程序来改变文件名:
————————————————————————————————————
import os, urllib, sys, getopt
class Renamer:
    
    input_encoding = ""
    output_encoding = ""
    path = ""
    is_url = False
    
    def __init__(self, input, output, path, is_url):
        self.input_encoding = input
        self.output_encoding = output
        self.path = path
        self.is_url = is_url
    
    def start(self):
        self.rename_dir(self.path)
    def rename(self, root, path):
        try:
            if self.is_url:
                new = urllib.unquote(path).decode(self.input_encoding).encode(self.output_encoding)
            else:
                new = path.decode(self.input_encoding).encode(self.output_encoding)
            os.rename(os.path.join(root, path), os.path.join(root, new))
        except:
            pass
    def rename_dir(self, path):
        for root, dirs, files in os.walk(path):
            for f in files:
                self.rename(root, f)
            if dirs == []:
                for f in files:
                    self.rename(root, f)
            else:
                for d in dirs:
                    self.rename_dir(os.path.join(root, d))
                    self.rename(root, d)
def usage():
    print '''This program can change encode of files or directories.
    Usage:   rename.py [OPTION]...
    Options:
        -h, --help                  this document.
        -i, --input-encoding=ENC    set original encoding, default is UTF-8.
        -o, --output-encoding=ENC   set output encoding, default is GBK.
        -p, --path=PATH             choose the path which to process.
        -u, --is-url                whether as a URL
    '''
def main(argv):
    input_encoding = "utf-8"
    output_encoding = "gbk"
    path = ""
    is_url = True
    
    try:
        opts, args = getopt.getopt(argv, "hi:o:p:u", ["help", "input-encoding=", "output-encoding=", "path=", "is-url"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-i", "--input-encoding"):
            input_encoding = arg
        elif opt in ("-o", "--output-encoding"):
            output_encoding = arg
        elif opt in ("-p", "--path"):
            path = arg
        elif opt in ("-u", "--is-url"):
            is_url = True
    rn = Renamer(input_encoding, output_encoding, path, is_url)
    rn.start()
if __name__ == '__main__':
    main(sys.argv[1:])
————————————————————————————————————
rename.py -i utf-8 -o gbk -p <指定的下载目录> -u
 

linux下使用wget下载整个网站的更多相关文章

  1. Linux下使用wget下载FTP服务器文件

    wget -nH -m --ftp-user=your_username --ftp-password=your_password ftp://your_ftp_host/* 使用命令下载ftp上的文 ...

  2. linux 下 使用wget 下载 jdk资源 命令

    wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-co ...

  3. wget下载整个网站

    wget下载整个网站wget下载整个网站可以使用下面的命令 wget -r -p -k -np http://hi.baidu.com/phps , -r 表示递归下载,会下载所有的链接,不过要注意的 ...

  4. LINUX下一款不错的网站压力测试工具webbench

    LINUX下一款不错的网站压力测试工具webbench 分类: Linux 2014-07-03 09:10 220人阅读 评论(0) 收藏 举报 [html] view plaincopy wget ...

  5. wget下载整个网站---比较实用--比如抓取Smarty的document

    wget下载整个网站可以使用下面的命令 wget -r -p -k -np http://hi.baidu.com/phps, -r 表示递归下载,会下载所有的链接,不过要注意的是,不要单独使用这个参 ...

  6. Linux下Apache服务部署静态网站------网站服务程序

    文章链接(我的CSDN博客): Linux下Apache服务部署静态网站------网站服务程序

  7. 简单备忘一下Linux下的wget和curl如何使用http proxy

    简单备忘一下Linux下的wget和curl如何使用http proxywget -e "http_proxy=porxyhost:port" www.baidu.comcurl ...

  8. Windows 和 Linux下使用socket下载网页页面内容(可设置接收/发送超时)的代码

    主要难点在于设置recv()与send()的超时时间,具体要注意的事项,请看代码注释部分,下面是代码: #include <stdio.h> #include <sys/types. ...

  9. wget下载整个网站或特定目录

    下载整个网站或特定目录 wget -c -k -r -np -p http://www.yoursite.com/path -c, –continue 断点下载 -k, –convert-links ...

随机推荐

  1. svn资源库url问题

    今天连接svn资源库的时候一直出现 RA layer request failedsvn: Unable to connect to a repository at URL http://... sv ...

  2. 接口测试工具postman(一)下载安装说明

    Postman是Google开发的一款功能强大的网页调试与发送网页HTTP请求,并能运行测试用例的的Chrome插件. 主要功能包括: 1.模拟各种HTTP requests 从常用的 GET.POS ...

  3. python接口测试(三)——Excell文件读取进行参数化

    python进行http请求时,需要对参数进行参数化,此时就可以运用Excel进行,具体如下: 1.梳理出请求中那些参数需要参数化,然后新建一个Excel,如图: 2.读取Excel中的内容,在读取前 ...

  4. 分享 go语言爬虫---开源项目Pholcus

    写在开头的话:记录一下最近学习Pholcus(https://github.com/henrylee2cn/pholcus)的过程,首先去学习的go基本语法,在没接触的时候发现很多不理解的地方,但是当 ...

  5. 九度OJ--1164(C++)

    #include <iostream>#include <vector> using namespace std; int main() { int n; // n为矩阵阶数 ...

  6. 编译 TensorFlow 的 C/C++ 接口

    TensorFlow 的 Python 接口由于其方便性和实用性而大受欢迎,但实际应用中我们可能还需要其它编程语言的接口,本文将介绍如何编译 TensorFlow 的 C/C++ 接口. 安装环境: ...

  7. 软工实践 - 第二十三次作业 Beta 冲刺(1/7)

    队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/10093337.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过 ...

  8. Android EditText 限制输入字符

    今天为简单的登录界面的输入框(用户名.密码框,验证码),均为EditText框,做输入限制,不能有空格,不能有一些特殊字符,不多说,直接上代码: /** * 禁止EditText输入空格 * * @p ...

  9. not1,not2,bind1st,bind2nd

    例子需要包含头文件 #include <vector> #include <algorithm> #include <functional> bind1st和bin ...

  10. OpenCV膨胀和腐蚀示例代码

    #include<cv.h> #include<highgui.h> int main(int argc, char** argv) { IplImage* img = cvL ...