#! /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=namedef 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()
到此这篇关于python使用urllib模块开发的多线程豆瓣小站mp3下载器就介绍到这了。对牛弹琴伤心的不是牛,先了解对象后,再“弹琴”。更多相关python使用urllib模块开发的多线程豆瓣小站mp3下载器内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!