本文主要是介绍批量打印酷狗音乐歌曲名,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
批量打印酷狗音乐歌曲名
突然想导出酷狗音乐的歌曲名,发现没有导出列表的选项了,尝试用python和html来解决。
**第一步:**在酷狗音乐里分享音乐列表,复制链接例子:
https://t1.kugou.com/ffPdl43BeV2
在网页中打开,然后打开列表:
**第二步:**按F12然后找到musicbox这个标签,把它缩小,右键复制:
**第三部:**打开python,新建一个脚本,替换成你的html内容,然后运行以下代码即可打印歌曲名:
from bs4 import BeautifulSouphtml_text = """
<div id="musicbox" class="musicbox "><div class="songjsAction" style="overflow: hidden; padding: 0px; width: 470px;"><div class="jspContainer" style="width: 470px; height: 360px;"><div class="jspPane" style="top: 0px; left: 0px; width: 470px;"><div class="musiclist"><li class="active"><div class="musiclist-item clearfix"><span class="musiclist-number">1</span><div class="musiclist-name"><span class="musiclist-songname-txt" title="空空如也">空空如也</span><div class="mod-list-menu"><a href="javascript:;" class="icon list-menu-item icon-playbar-download list-action-down" title="下载"><i class="icon list-menu-icon-down"></i><span class="icon_txt">下载</span></a><a href="javascript:;" class="icon list-menu-item icon-playbar-share list-action-share" title="分享"><i class="icon list-menn-icon-share"></i><span class="icon_txt">分享</span></a><a href="javascript:;" class="icon list-menu-item list-menu-icon-del list-action-del" title="删除歌曲"><i class="icon list-menu-icon-add"></i><span class="icon_txt">删除</span></a></div></div><div class="musiclist-artist" title="胡66">胡66</div><div class="musiclist-time">03:31</div></div></li><li><div class="musiclist-item clearfix"><span class="musiclist-number">2</span><div class="musiclist-name"><span class="musiclist-songname-txt" title="Bend Ova (Explicit)">Bend Ova (Explicit)</span><div class="mod-list-menu"><a href="javascript:;" class="icon list-menu-item icon-playbar-download list-action-down" title="下载"><i class="icon list-menu-icon-down"></i><span class="icon_txt">下载</span></a><a href="javascript:;" class="icon list-menu-item icon-playbar-share list-action-share" title="分享"><i class="icon list-menn-icon-share"></i><span class="icon_txt">分享</span></a><a href="javascript:;" class="icon list-menu-item list-menu-icon-del list-action-del" title="删除歌曲"><i class="icon list-menu-icon-add"></i><span class="icon_txt">删除</span></a></div></div><div class="musiclist-artist" title="Lil Jon、Tyga">Lil Jon、Tyga</div><div class="musiclist-time">03:46</div></div></li><li class=""><div class="musiclist-item clearfix"><span class="musiclist-number">3</span><div class="musiclist-name"><span class="musiclist-songname-txt" title="Faded">Faded</span><div class="mod-list-menu"><a href="javascript:;" class="icon list-menu-item icon-playbar-download list-action-down" title="下载"><i class="icon list-menu-icon-down"></i><span class="icon_txt">下载</span></a><a href="javascript:;" class="icon list-menu-item icon-playbar-share list-action-share" title="分享"><i class="icon list-menn-icon-share"></i><span class="icon_txt">分享</span></a><a href="javascript:;" class="icon list-menu-item list-menu-icon-del list-action-del" title="删除歌曲"><i class="icon list-menu-icon-add"></i><span class="icon_txt">删除</span></a></div></div><div class="musiclist-artist" title="Alan Walker">Alan Walker</div><div class="musiclist-time">03:32</div></div></li><li class=""><div class="musiclist-item clearfix"><span class="musiclist-number">4</span><div class="musiclist-name"><span class="musiclist-songname-txt" title="Welcome to Planet Urf (欢迎来到海牛星)">Welcome to Planet Urf (欢迎来到海牛星)</span><div class="mod-list-menu"><a href="javascript:;" class="icon list-menu-item icon-playbar-download list-action-down" title="下载"><i class="icon list-menu-icon-down"></i><span class="icon_txt">下载</span></a><a href="javascript:;" class="icon list-menu-item icon-playbar-share list-action-share" title="分享"><i class="icon list-menn-icon-share"></i><span class="icon_txt">分享</span></a><a href="javascript:;" class="icon list-menu-item list-menu-icon-del list-action-del" title="删除歌曲"><i class="icon list-menu-icon-add"></i><span class="icon_txt">删除</span></a></div></div><div class="musiclist-artist" title="英雄联盟">英雄联盟</div><div class="musiclist-time">02:14</div></div></li><li class=""><div class="musiclist-item clearfix"><span class="musiclist-number">5</span><div class="musiclist-name"><span class="musiclist-songname-txt" title="小烦恼没什么大不了 (抢听版)">小烦恼没什么大不了 (抢听版)</span><div class="mod-list-menu"><a href="javascript:;" class="icon list-menu-item icon-playbar-download list-action-down" title="下载"><i class="icon list-menu-icon-down"></i><span class="icon_txt">下载</span></a><a href="javascript:;" class="icon list-menu-item icon-playbar-share list-action-share" title="分享"><i class="icon list-menn-icon-share"></i><span class="icon_txt">分享</span></a><a href="javascript:;" class="icon list-menu-item list-menu-icon-del list-action-del" title="删除歌曲"><i class="icon list-menu-icon-add"></i><span class="icon_txt">删除</span></a></div></div><div class="musiclist-artist" title="许嵩">许嵩</div><div class="musiclist-time">03:32</div></div></li><li class=""><div class="musiclist-item clearfix"><span class="musiclist-number">6</span><div class="musiclist-name"><span class="musiclist-songname-txt" title="违章动物">违章动物</span><div class="mod-list-menu"><a href="javascript:;" class="icon list-menu-item icon-playbar-download list-action-down" title="下载"><i class="icon list-menu-icon-down"></i><span class="icon_txt">下载</span></a><a href="javascript:;" class="icon list-menu-item icon-playbar-share list-action-share" title="分享"><i class="icon list-menn-icon-share"></i><span class="icon_txt">分享</span></a><a href="javascript:;" class="icon list-menu-item list-menu-icon-del list-action-del" title="删除歌曲"><i class="icon list-menu-icon-add"></i><span class="icon_txt">删除</span></a></div></div><div class="musiclist-artist" title="许嵩">许嵩</div><div class="musiclist-time">04:09</div></div></li><li class=""><div class="musiclist-item clearfix"><span class="musiclist-number">7</span><div class="musiclist-name"><span class="musiclist-songname-txt" title="胡萝卜须">胡萝卜须</span><div class="mod-list-menu"><a href="javascript:;" class="icon list-menu-item icon-playbar-download list-action-down" title="下载"><i class="icon list-menu-icon-down"></i><span class="icon_txt">下载</span></a><a href="javascript:;" class="icon list-menu-item icon-playbar-share list-action-share" title="分享"><i class="icon list-menn-icon-share"></i><span class="icon_txt">分享</span></a><a href="javascript:;" class="icon list-menu-item list-menu-icon-del list-action-del" title="删除歌曲"><i class="icon list-menu-icon-add"></i><span class="icon_txt">删除</span></a></div></div><div class="musiclist-artist" title="许嵩">许嵩</div><div class="musiclist-time">03:51</div></div></li><li class=""><div class="musiclist-item clearfix"><span class="musiclist-number">8</span><div class="musiclist-name"><span class="musiclist-songname-txt" title="玫瑰花的葬礼">玫瑰花的葬礼</span><div class="mod-list-menu"><a href="javascript:;" class="icon list-menu-item icon-playbar-download list-action-down" title="下载"><i class="icon list-menu-icon-down"></i><span class="icon_txt">下载</span></a><a href="javascript:;" class="icon list-menu-item icon-playbar-share list-action-share" title="分享"><i class="icon list-menn-icon-share"></i><span class="icon_txt">分享</span></a><a href="javascript:;" class="icon list-menu-item list-menu-icon-del list-action-del" title="删除歌曲"><i class="icon list-menu-icon-add"></i><span class="icon_txt">删除</span></a></div></div><div class="musiclist-artist" title="许嵩">许嵩</div><div class="musiclist-time">04:19</div></div></li></div></div></div></div></div>
"""soup = BeautifulSoup(html_text, 'html.parser')
song_elements = soup.find_all(class_="musiclist-songname-txt")
for element in song_elements:song_title = element['title']print(song_title)
然后发现最多只能打印100首
这篇关于批量打印酷狗音乐歌曲名的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!