Python代碼搜索並下載酷狗音樂

運行環境:php

Python3.5+Pycharmurl

實例代碼:spa

 

 1 import requests,re
 2 
 3 keyword = input("請輸入想要聽的歌曲:")
 4 url = "http://songsearch.kugou.com/song_search_v2?callback=jQuery1124006980366032059648_1518578518932&keyword="+keyword+"&page=1&pagesize=30&userid=-1&clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1&privilege_filter=0&_=1518578518934"
 5 content = requests.get(url)
 6 filehash = re.findall('"FileHash":"(.*?)"',content.text)[0]
 7 songname = re.findall('"SongName":"(.*?)"',content.text)[0].replace("<\\/em>","").replace("<em>","")
 8 
 9 hash_url = "http://www.kugou.com/yy/index.php?r=play/getdata&hash="+filehash
10 hash_content = requests.get(hash_url)
11 play_url = re.findall('"play_url":"(.*?)"',hash_content.text)
12 play_url = ''.join(play_url)
13 real_download_url = play_url.replace("\\","")
14 
15 print("客官,請稍等一下,好音樂立刻呈上!")
16 with open(songname+".mp3","wb")as fp:
17     fp.write(requests.get(real_download_url).content)
相關文章
相關標籤/搜索