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

大家快瞧那结冰的湖水,春风一吹冰都融化了,河里的小鱼都游出海面,在湖水中自由的游来游去,多可爱的小鱼啊!多么欢快的小鱼啊!真是让人深深的为它那可爱的摸样着迷。春风一吹过那枯黄的小草身边时,小草突然边了摸样,它从原来的枯黄变成了嫩绿,慢慢地小草从嫩绿变成了鲜绿渐渐地越变越绿,绿的让人难以相信那是小草。啊!小草我为你的样子感到是个奇迹。

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