Python-demo(listen)


Requests Import
Import json
request for acquiring data # reptile principle simulation browser


#点击播放连接
#url = "https://www.ximalaya.com/revision/play/album?albumId=297790&pageNum=1&sort=1&pageSize=30"
url = "https://www.ximalaya.com/revision/play/album?albumId=333001&pageNum=1&sort=1&pageSize=30"
#保存的身份信息
header = {
     "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36"
}

Url # acquires the content of the string in response obtained json format.
Response = requests.get (url, header = headers) .text
#Print (response)
# json format into the data dictionary
audio_data = json.loads (response) [ "Data"] [ "tracksAudioPlay"]
Print (audio_data)
# src acquiring element acquires each connected
for AUDIO_info in audio_data:
     music_url AUDIO_info = [ "src"]
     music_name1 AUDIO_info = [ "trackName"]

  Print # (AUDIO_info)
   # slice split dictionary to come up with the name
     music_name = music_url.split ( "/") [- 1]
     Print (music_name1) # audio file name of the
     print (music_name) #url the name m4a audio file
     print (music_url ) links the audio file #

    # Music_name formatted output parameter stored in the music file: path placeholder, format name, a file format to the alias F
     with Open ( "Music1 /" + + music_name1 ".mp3", "WB") AS F: # Here create a file name: brothers and friends love to make money
     # # audio content to get from where
         f.write (requests.get (music_url) .content)

Guess you like

Origin www.cnblogs.com/Chen-MJ/p/11422948.html