ImportRequestsImportRe#get hush values and albumIDdefGethush ():Globalmusicname Musicname= Input ('Please enter the name of the song you want to download:') URL='Http://songsearch.kugou.com/song_search_v2?callback=jQuery1910026785707623246724_1490845878865&keyword ={}&page=1&pagesize=30&userid=-1&%20%20clientver=&platform=webfilter&tag=em&filter =2&iscorrection=1&privilege_filter=0&_=1490845878887'. Format (musicname) Response=requests.get (URL) HTML=Response.text Pattern='" Filehash": "(. *?)", "Sqpaytype". *? " albumID ":" (. *?) "'Hush= Re.search (pattern,html). Group (1) Album= Re.search (pattern,html). Group (2) returnHush#Get music download linkdefGetmusicurl (Hush): URL='http://www.kugou.com/yy/index.php?r=play/getdata&hash={}'. Format (Hush) response=requests.get (URL) HTML=Response.text Pattern='" Play_url": "(. *?)", "authors"'Music_url= Re.search (pattern,html). Group (1) returnMusic_url#Download Musicdefdownloadmusic (URL): Session=requests. Session () URL= Url.replace ('\\',"') R=requests.get (URL) with open (R'D:\mp3\%s.mp3'% Musicname,"WB") as F: forChunkinchR.iter_content (chunk_size=512): ifChunk:Print('Downloading:%s'%musicname) f.write (chunk)defMain (): Downloadmusic (Getmusicurl (Gethush ()))if __name__=='__main__': Main ()
Python download cool Dog music Source