-
python入门教程之使用Python爬虫的方式把自己喜欢的音乐的歌词爬取到本地
试听地址 https://www.xin3721.com/eschool/pythonxin3721/
前言
本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理。
闲来无事听听歌,听到无聊唠唠嗑,你有没有特别喜欢的音乐,你有没有思考或者尝试过把自己喜欢的歌曲的歌词全部给下载下来呢?
没错,我这么干了,今天我们以QQ音乐为例,使用Python爬虫的方式把自己喜欢的音乐的歌词爬取到本地!

下面就来详细讲解如何一步步操作,文末附完整代码。
01
寻找真正的客户端(client_search)(客户端搜索)
搜索网站:https://y.qq.com/,打开QQ音乐网站。

然后搜索想要的歌手,右击鼠标,点击检查。

然后选中Network,并点击蓝色底纹的页面

02
找到真正的url

瞧见是不是很头疼,别担心,你只需要这些(
https://c.y.qq.com/soso/fcgi-bin/client_search_cp),后面的都是参数(说法不是很准确)
03
写入参数

在这个位置下的所有参数复制过来,就像这样

我们不难发现,p代表的是页数(我这里使用了循环,详情看一下代码),w的话代表歌手名字(可以进行更改)
然后我们可以获取到歌手的名字,歌曲专辑,音频时间,播放链接(这一部分的代码在parse_page这个函数中)

然后就到了最要命的歌词环节,shit,头疼
04
1、点击歌词,Network


我们可以看到一页只有5首歌的歌词,然后我们进行爬取(在lyric_a代码中)
2、我们需要更改params参数,同样在最下面,与上面寻找一致
3、使用openyxl放入excel表格中
(1)导入openyxl模块

(2)创建

(3)放入并命名excel

这是例图
这里不用csv是因为初学,技术太菜,出来全是逗号(真·逗号分隔符)

加企鹅群695185429即可免费获取,资料全在群文件里。资料可以领取包括不限于Python实战演练、PDF电子文档、面试集锦、学习资料等