利用Python爬虫批量下载网易云音乐歌单歌曲
2018-07-05 13:23
1086 查看
[code]from tkinter import * import requests from bs4 import BeautifulSoup from urllib.request import urlretrieve def download(): url = entry.get() new_url = url.replace('/#', '') header = { 'Host': 'music.163.com', 'Referer': 'https://music.163.com/', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0' } res = requests.get(new_url, headers=header).text r = BeautifulSoup(res, "html.parser") music_dict = {} result = r.find('ul', {'class', 'f-hide'}).find_all('a') for music in result: print(music) music_id = music.get('href').strip('/song?id=') music_name = music.text music_dict[music_id] = music_name for song_id in music_dict: song_url = "http://music.163.com/song/media/outer/url?id=%s" % song_id path = "E:\\python demo\wangyiyunmusic\%s.mp3" % music_dict[song_id] # 添加数据 text.insert(END, "正在下载:%s" % music_dict[song_id]) text.see(END) text.update() urlretrieve(song_url, path) root = Tk() root.title("网易云音乐下载器") root.geometry("550x400+550+230") label = Label(root, text="歌单URL", font=('宋体', 15)) label.grid() entry = Entry(root, font=('微软雅黑', 20)) entry.grid(row=0, column=1) text = Listbox(root, font=("微软雅黑", 15), width=45, height=10) text.grid(row=1, columnspan=2) button = Button(root, text="开始下载", font=("微软雅黑", 15), command=download) button.grid(row=2, column=0, sticky=W) button1 = Button(root, text="退出", font=("微软雅黑", 15), command=root.quit) button1.grid(row=2, column=1, sticky=E) mainloop()
阅读更多
相关文章推荐
- Python爬虫——利用新浪微盘下载周杰伦的歌曲(共190首)
- 一步步分析百度音乐的播放地址,利用Python爬虫批量下载
- 一步步分析百度音乐的播放地址,利用Python爬虫批量下载
- Python爬虫之网易云音乐下载
- Python 利用scrapy爬虫通过短短50行代码下载整站短视频
- 【Python3爬虫】下载酷狗音乐上的歌曲
- 利用Python脚本实现-----登陆新浪微博&批量下载收藏内容
- Python实现简单爬虫功能--批量下载百度贴吧里的图片
- Python爬虫下载QQ音乐网站歌曲
- 批量下载小说网站上的小说(python爬虫)
- Python爬虫——request实例:爬取网易云音乐华语男歌手top10歌曲
- 利用Python编写网络爬虫下载文章
- 用Python 爬虫批量下载PDF文档
- Python3 scrapy下载网易云音乐所有(大部分)歌曲
- Python爬虫学习记录(3)——用Python获取虾米加心歌曲,并获取MP3下载地址
- 【爬虫之路】批量下载5sing上一位歌手的全部歌曲
- Python3 scrapy下载网易云音乐所有(大部分)歌曲
- 从零开始写Python爬虫 --- 1.7 爬虫实践: 排行榜小说批量下载
- 利用python 批量下载美拍视频
- Python爬虫(二)--利用百度地图API批量获取城市所有的POI点