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

yipeiwu_com6年前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)

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

相关文章

python 实现list或string按指定分段

我就废话不多说了,直接上代码吧! #方法一 def list_cut(mylist,count): length=len(mylist) merchant=length//c...

Python3最长回文子串算法示例

本文实例讲述了Python3最长回文子串算法。分享给大家供大家参考,具体如下: 1. 暴力法 思路:对每一个子串判断是否回文 class Solution: def longes...

浅析python打包工具distutils、setuptools

浅析python打包工具distutils、setuptools

python中安装包的方式有很多种: 源码包:python setup.py install 在线安装:pip install 包名(linux) / easy_install...

Python json模块dumps、loads操作示例

本文实例讲述了Python json模块dumps、loads操作。分享给大家供大家参考,具体如下: python中json数据的使用。 dumps和loads也是需要成对使用的,就像c...

python pandas 对series和dataframe的重置索引reindex方法

reindex更多的不是修改pandas对象的索引,而只是修改索引的顺序,如果修改的索引不存在就会使用默认的None代替此行。且不会修改原数组,要修改需要使用赋值语句。 series.r...