1 Star 0 Fork 0

lunny / LPan

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
gevent.py 1016 Bytes
一键复制 编辑 原始数据 按行查看 历史
lunny 提交于 2012-12-21 09:38 . updated
#! /usr/bin/python2.7
# -- coding:utf-8 --
#可以参考我的博客:http://www.cnblogs.com/descusr
import urllib,urllib2,gevent,re
from gevent import monkey
monkey.patch_all()
def worker(reg, url):
response=urllib.urlopen(url)
text=response.read()
groups=re.finditer(reg, text)
m_arr = []
for g in groups:
name=g.group(1).strip() + ".mp3"
path=g.group(2).replace('\\', '')
m_arr.append((name, path))
return m_arr
def grun(path, name):
urllib.urlretrieve(path, name)
if __name__ == '__main__':
#匹配音乐url
reg=re.compile('{"name":"(.+?)".+?"rawUrl":"(.+?)",.+?}', re.I)
musicArray = worker(reg, "http://site.douban.com/huazhou/")
jobs = []
for (name, path) in musicArray:
jobs.append(gevent.spawn(grun, path, name))
gevent.joinall(jobs)
Python
1
https://gitee.com/lunny/lpan.git
git@gitee.com:lunny/lpan.git
lunny
lpan
LPan
master

搜索帮助