转自: http://blog.itpub.net/29867/viewspace-716088/ 

(修改部分内容)

wget --restrict-file-name=ascii -m -c -nv -np -k -E -p http://www.w3school.com.cn/
wget --restrict-file-name=ascii -m -c -nv -np -k -E -p http://scrapy-chs.readthedocs.org

参数释义如下:

--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

文件改名方法来自于http://blog.csdn.net/kowity/article/details/6899256

wget下载整个网站的方法的更多相关文章

  1. linux下使用wget下载整个网站

    linux下可以用wget下载整个网站,而且网站链接中包含utf-8编码的中文也能正确处理. 简要方法记录如下: wget --restrict-file-name=ascii -m -c -nv - ...

  2. wget下载整个网站

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

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

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

  4. 为什么wget只下载某些网站的index.html? wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com wget 下载整个网站,或者特定目录

    wget -c -r -np -k -L -p http://blog.hesheyou.me -c, –continue 接着下载没下载完的文件 -r, –recursive 递归下载 -np, – ...

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

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

  6. wget 下载整个网站,或者特定目录

    需要下载某个目录下面的所有文件.命令如下 wget -c -r -np -k -L -p www.xxx.org/pub/path/ 在下载时.有用到外部域名的图片或连接.如果需要同时下载就要用-H参 ...

  7. Centos下wget下载整个网站,或者目录全部文件

    需要下载某个目录下面的所有文件.命令如下 wget -c -r -np -k -L -p www.xxx.org/pub/path/ 在下载时.有用到外部域名的图片或连接.如果需要同时下载就要用-H参 ...

  8. [转]wget 下载整个网站,或者特定目录

    FROM : http://www.cnblogs.com/lidp/archive/2010/03/02/1696447.html 需要下载某个目录下面的所有文件.命令如下 wget -c -r - ...

  9. [No00006B]方便的网络下载工具wget 可下载网站目录下的所有文件(可下载整个网站)

    wget是linux下命令行的下载工具,功能很强大,它能完成某些下载软件所不能做的,比如如果你想下载一个网页目录下的所有文件,如何做呢?网络用户有时候会遇到需要下载一批文件的情况,有时甚至需要把整个网 ...

随机推荐

  1. linux-shell——04

    mv 移动文件或者目录 格式:mv [选项]      源文件/目录     目标文件/目录 注:若移动目标位置与源位置相同(当前下操作),则此操作相当于重命名(改名) ex: [root@local ...

  2. Mybatis中updateByPrimaryKeySelective和updateByPrimaryKey区别

    int updateByPrimaryKeySelective(TbItem record); int updateByPrimaryKey(TbItem record); 上面的是逆转工程生成的Ma ...

  3. filter() 函数的使用

    Python3 filter() 函数 描述 filter() 函数用于过滤序列,过滤掉不符合条件的元素,返回一个迭代器对象,如果要转换为列表,可以使用 list() 来转换. 该接收两个参数,第一个 ...

  4. 笔记-python-多线程-深入-1

    笔记-python-多线程-深入-1 1.      线程池 1.1.    线程池:控制同时存在的线程数量 threading没有线程池,只能自己控制线程数量. 基本有两种方式: 每间隔一段时间创建 ...

  5. Flume是什么

    分布式流式实时收集日志文件系统,便于实时在线的流式计算,常配合 Storm 和 spark streming 使用. Flume is a distributed分布式的, reliable可靠的, ...

  6. idea无法新建maven项目

    之前用的都是eclipse,自从4月底入职新公司后,接触到了idea. 然后自己的电脑上也安装了idea,不过一直都没用,直到昨天打算开起来使用一下. 之后就是想新建一个maven项目,发现死活也新建 ...

  7. laravel5.5http会话机制

    1.配置文件 config/session.php 大多数是用file驱动,将session保存在storage/framework/sessions,可以考虑使用redis或者memcached 驱 ...

  8. PowerShell脚本授权最佳实践

    [TechTarget中国原创] Windows PowerShell已成为微软在Windows Server上提供的首选管理界面.因为深度整合到Windows Server操作系统,PowerShe ...

  9. LeetCode - Merge Interval.

    Merge Intervals 2014.2.26 21:28 Given a collection of intervals, merge all overlapping intervals. Fo ...

  10. Caliburn micro 学习笔记...

    页面跳转 LLS 结合 CM 使用方法 事件处理