码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-03-08 02:47:19      阅读:679      评论:0      收藏:0      [点我收藏+]

标签:user   cti   body   mp3   arc   callback   file   ugo   put   

运行环境:

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

 

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

标签:user   cti   body   mp3   arc   callback   file   ugo   put   

原文地址:https://www.cnblogs.com/hanxiaobei/p/8525674.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!