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?%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)
以上就是本文分享的全部代码了,希望大家能够喜欢。