复制代码 代码如下:
import os, urllib,urllib2, thread,threading
import re
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()
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8