Python代码搜索并下载酷狗音乐

运行环境:

Python3.5+Pycharm

实例代码:

 

 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("","")
 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)

 

转载于:https://www.cnblogs.com/hanxiaobei/p/8525674.html

你可能感兴趣的:(Python代码搜索并下载酷狗音乐)