使用Python实现下载网易云音乐的高清MV

yipeiwu_com5年前Python基础

Python下载网易云音乐的高清MV,没有从首页进去解析,直接循环了....

downPage1.py

复制代码 代码如下:

#coding=utf-8
import urllib
import re
import os
def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html
def getVideo(html):
    reg = r'hurl=(.+?\.jpg)'
    imgre = re.compile(reg)
    imglist = re.findall(imgre,html)
    return imglist
for num in range(28000,1000000):
    print num
    html = getHtml("http://music.163.com/mv?id=%s"%num)
    parsed = getVideo(html)
    if  len(parsed)==0:
        continue
    vedioUrls = parsed[0].split("&")
    artist = vedioUrls[4].split("=")[1].decode('utf-8').strip()
    song = vedioUrls[3].split("=")[1].decode('utf-8').strip()
    if  len(vedioUrls[0])==0:
        continue
    filename = '%s/%s.mp4' %(artist,song)
    if "/" in song:
        continue
    if os.path.exists(filename):
        print 'the MV file exists.%s'%num
    else:
        print 'the MV is downloding.%s'%num
        if  os.path.exists(artist):
            print ""
        else:
            os.makedirs(artist)
        urllib.urlretrieve(vedioUrls[0],filename)

以上就是本文分享的全部代码了,希望大家能够喜欢。

相关文章

python2.7 json 转换日期的处理的示例

python2.7中 集成了json的处理(simplejson),但在实际应用中,从mysql查询出来的数据,通常有日期格式,这时候,会报一个错: TypeError: datetim...

Python解决鸡兔同笼问题的方法

本文实例讲述了Python解决鸡兔同笼问题的方法,分享给大家供大家参考。具体分析如下: 问题描述 一个笼子里面关了鸡和兔子(鸡有 2 只脚,兔子有 4 只脚,没有例外)。已经知道了笼 子...

pygame游戏之旅 添加键盘按键的方法

pygame游戏之旅 添加键盘按键的方法

本文为大家分享了pygame游戏之旅的第4篇,供大家参考,具体内容如下 按键类型用event.type表示,按键用event.key表示 KEYDOWN和KEYUP的参数描述如下: k...

Python入门教程之运算符与控制流

Python入门教程之运算符与控制流

Python 中的运算符 什么是运算符?举个简单的例子 4 +5 = 9 。 例子中,4 和 5 被称为操作数,"+" 称为运算符。 1 . 求幂运算符 在 Java 中如果我们想对一...

Python的多态性实例分析

本文实例讲述了Python的多态性。分享给大家供大家参考。具体如下: #!/usr/bin/env python # polymorphism in python # class b...