Operating Environment:
Python3.5+pycharm
Instance code:
1 Import Requests,re2 3Keyword = input ("Please enter the song you want to listen to:")4URL ="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"5Content = requests.Get(URL)6Filehash = Re.findall ('" Filehash": "(. *?)"', Content.text) [0]7Songname = Re.findall ('" Songname": "(. *?)"', Content.text) [0].replace ("<\\/em>",""). Replace ("<em>","")8 9Hash_url ="http://www.kugou.com/yy/index.php?r=play/getdata&hash="+FilehashTenHash_content = requests.Get(Hash_url) OnePlay_url = Re.findall ('" Play_url": "(. *?)"', Hash_content.text) APlay_url ="'. Join (Play_url) -Real_download_url = Play_url.replace ("\\","") - thePrint"sir, please wait a moment, good music will be presented immediately! ") -With open (songname+". mp3","WB") asfp: -Fp.write (requests.Get(Real_download_url). Content)
Python code search and download Cool dog music