This article will share with you the idea of downloading the HD music video code of NetEase Cloud Music in Python. I am a newbie and have not done any special functions. I just loop through the id of the music video directly, you can expand it on your own. Python downloads the high-definition music videos of NetEase Cloud Music. it does not go into the analysis from the home page and loops directly ....
DownPage1.py
The code is as follows:
# 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,000000 ):
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)
The above is all the code shared in this article. I hope you will like it.