铁雪资源网 Design By www.gsvan.com

复制代码 代码如下:
#! /usr/bin/python2.7
# -- coding:utf-8 --

import os, urllib,urllib2, thread,threading
import re

#匹配音乐url
reg=re.compile('{"name":"(.+?)".+?"rawUrl":"(.+?)",.+?}', re.I)


class downloader(threading.Thread):
        def __init__(self, url, name):
                threading.Thread.__init__(self)
                self.url=url
                self.name=name

        def run(self):
                print 'downloading from %s' % self.url
                urllib.urlretrieve(self.url, self.name)

threads=[]

#多线程下载文件
def main(url):
        response=urllib.urlopen(url)
        text=response.read()
        groups=re.finditer(reg, text)
        for g in groups:
                name=g.group(1).strip() + ".mp3"
                path=g.group(2).replace('\\', '')
                t=downloader(path, name)
                threads.append(t)
                t.start()

                                                                                                                                                     
if __name__ == '__main__':
        main("http://site.douban.com/huazhou/")
        for t in threads:
                t.join()

标签:
豆瓣小站,mp3下载,urllib模块,多线程

铁雪资源网 Design By www.gsvan.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
铁雪资源网 Design By www.gsvan.com

评论“python使用urllib模块开发的多线程豆瓣小站mp3下载器”

暂无python使用urllib模块开发的多线程豆瓣小站mp3下载器的评论...