from tkinter import * import requests import re import threading
#首先设置一下ua和url headers = { ‘Referer‘:‘https://music.163.com/‘ “User-Agent“: “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML like Gecko) Chrome/67.0.3396.99 Safari/537.36“ }
#找到要下载歌单界面 def get_page(): #获取输入 id = entry.get() #获取歌单 url = “https://music.163.com/playlist?id=%s“%str(id) #发送请求 res = requests.get(urlheaders=headers) #寻找u需要下载的数据!正则:/d 任意数字 .*?寻找符合的替换 data = re.findall(r‘(.*?)‘ res.text) get_songs(data) text.insert(END ‘歌单下载完毕‘) text.see(text.size() - 1) def get_songs(data): for i in data: download_url = “http://music.163.com/song/media/outer/url?id=%s“ % i[0] text.insert(END ‘正在下载>>>>:‘ + i[1]) try: with open(‘music/‘ + i[1]+‘.mp3‘ ‘wb‘) as f: f.write(requests.get(download_url).content) text.insert(END
评论
共有 条评论