python爬取网易云飙升榜数据
首先,我们打开网易云网页版,击排行榜,然后点击左侧云音乐飙升榜,如图:
使用开发者工具找到我们需要的数据:
源码:
import requests from lxml import etree import re import json import urllib import xlwt import csv url = "https://music.163.com/discover/toplist?id=19723756" headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'} workbook=xlwt.Workbook(encoding='utf-8') globals() wooksheet=workbook.add_sheet('歌曲') wooksheet.write(0,0,'歌曲名') wooksheet.write(0,1,'歌手名') wooksheet.write(0,2,'专辑名') wooksheet.write(0,3,'歌词') wooksheet.write(0,4,'评论') response = requests.get(url,headers=headers) html = etree.HTML(response.text) ids = html.xpath('//ul[@class="f-hide"]//a/@href') for i in range(len(ids)):ids[i] = re.sub('\D', '', ids[i]) # print(ids) # list=[] for i in range(len(ids)):music_url = f"https://music.163.com/song?id={ids[i]}"response = requests.get(music_url,headers=headers)html = etree.HTML(response.text)music_info = html.xpath('//title/text()')ly=f'http://music.163.com/api/song/lyric?' + 'id=' + str(ids[i]) + '&lv=1&kv=1&tv=-1'res=requests.get(ly,headers=headers)json_obj=res.textj=json.loads(json_obj)lrc=j['lrc']['lyric']pat=re.compile(r'\[.*\]')lrc=re.sub(pat,"",lrc)lrc=lrc.strip()rl = 'http://music.163.com/weapi/v1/resource/comments/R_SO_4_' + ids[i] + '?csrf_token='data = {'params': 'zC7fzWBKxxsm6TZ3PiRjd056g9iGHtbtc8vjTpBXshKIboaPnUyAXKze+KNi9QiEz/IieyRnZfNztp7yvTFyBXOlVQP/JdYNZw2+GRQDg7grOR2ZjroqoOU2z0TNhy+qDHKSV8ZXOnxUF93w3DA51ADDQHB0IngL+v6N8KthdVZeZBe0d3EsUFS8ZJltNRUJ','encSecKey': '4801507e42c326dfc6b50539395a4fe417594f7cf122cf3d061d1447372ba3aa804541a8ae3b3811c081eb0f2b71827850af59af411a10a1795f7a16a5189d163bc9f67b3d1907f5e6fac652f7ef66e5a1f12d6949be851fcf4f39a0c2379580a040dc53b306d5c807bf313cc0e8f39bf7d35de691c497cda1d436b808549acc'}postdata = urllib.parse.urlencode(data).encode('utf8') # 进行编码request = urllib.request.Request(rl, headers=headers, data=postdata)reponse = urllib.request.urlopen(request).read().decode('utf8')json_dict = json.loads(reponse) # 获取jsonhot_commit = json_dict['hotComments']music_name = music_info[0].split('-')[0]singer=music_info[0].split('-')[1]dis = html.xpath("//div[@class='cnt']//p[@class='des s-fc4']//a/@href")for a in range(len(dis)):dis[a] = re.sub('\D', '', dis[a])isd=dis[1]result= isd.split('\n')uli=[]for c in range(len(result)):music_albums = f"https://music.163.com/album?id={result[c]}"rse=requests.get(music_albums,headers=headers)html = etree.HTML(rse.text)album=html.xpath("//h2/text()")wooksheet.write(i+1,2,album)for item in hot_commit:# list.append(item['content'])mi=item['content']wooksheet.write(i+1,0,music_name)wooksheet.write(i+1,1,singer)wooksheet.write(i+1,3,lrc)wooksheet.write(i+1,4,mi)workbook.save(r'C:\Users\8615\Desktop\song.xls')try:print('正在下载', music_name)urllib.request.urlretrieve(music_url, './%s.mp3' % music_name)print('下载成功')except:print('下载失败')
Pycharm运行结果
爬取到的名字、歌手、所属专辑、歌词、歌曲、评论信息保存到csv文件中
下载到的歌曲文件
python爬取网易云飙升榜数据相关推荐
- python爬取网易云音乐排行榜数据
python爬取网易云音乐排行榜歌曲及评论 网易云音乐排行榜歌曲及评论爬取 主要注意问题:selenium 模拟登录.iframe标签定位.页面元素提取. 在利用selenium定位元素并取值的过程中 ...
- python爬取网易云音乐飙升榜音乐_python爬取网易云音乐热歌榜 python爬取网易云音乐热歌榜实例代码...
想了解python爬取网易云音乐热歌榜实例代码的相关内容吗,FXL在本文为您仔细讲解python爬取网易云音乐热歌榜的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:python,网易热歌榜 ...
- python爬取网易云音乐飙升榜音乐_python爬取网易云音乐热歌榜实例代码
首先找到要下载的歌曲排行榜的链接,这里用的是: https://music.163.com/discover/toplist?id=3778678 然后更改你要保存的目录,目录要先建立好文件夹,例如我 ...
- Python爬取网易云热歌榜所有音乐及其热评
获取特定歌曲热评: 首先,我们打开网易云网页版,击排行榜,然后点击左侧云音乐热歌榜,如图: 关于如何抓取指定的歌曲的热评,参考这篇文章,很详细,对小白很友好: 手把手教你用Python爬取网易云40万 ...
- Python爬取网易云音乐热歌榜(爬虫)
Python爬取网易云音乐热歌榜歌曲,并下载到本地 找到要下载歌曲排行榜的链接,这里用的是: https://music.163.com/discover/toplist?id=3778678 然后更 ...
- python爬取网易云热歌榜
Python爬取网易云音乐热歌榜歌曲,并下载到本地 找到要下载歌曲排行榜的链接,这里用的是: https://music.163.com/discover/toplist?id=3778678 #网易 ...
- 爬取网易云歌曲榜单中网易云歌曲及其对应id xpath csv re requests python
基操爬取网易云歌曲榜单中网易云歌曲及其对应id 回顾xpath csv re requests 先进行基础抓包! 1 2 3 然后就是代码啦,兄弟们,我的代码都很完整,看懂思路,直接收藏复制粘贴就可以 ...
- Python爬取网易云音乐歌手歌曲和歌单(爬虫)
Python爬取网易云音乐歌手歌曲和歌单 是 仅供学习参考 Python爬取网易云音乐网易云音乐歌手歌曲和歌单,并下载到本地 ①找到要下载歌手歌曲的链接,这里用的是: https://music.16 ...
- Python爬取网易云歌曲评论,做词云分析
前言 emmmm 没什么说的,想说的都在代码里 环境使用 Python 3.8 解释器 3.10 Pycharm 2021.2 专业版 selenium 3.141.0 本次要用到selenium模块 ...
- python爬取网易云音乐歌曲
python爬取网易云歌曲并且保存到本地 打开网易云音乐首页随便打开了一个歌单列表(https://music.163.com/#/playlist?id=924680166) 先贴代码为敬 impo ...
最新文章
- 2018 年最引人注目的科学时刻,《科学》杂志选出14 张年度最佳科学照片
- python程序实例教程基础-编程小案例
- 【BZOJ 4057 Kingdoms】
- 定位漏水与非定位漏水的区别?
- 从原理上理解MySQL的优化建议
- Leetcode226. 翻转二叉树(递归、迭代、层序三种解法)
- 前端代码获取文件大小_vue技术栈前端建设方案
- python1e2_Python必修基础(1)
- Unable to update index for central|http://repo1.maven.org/maven2
- java除法运算符号怎么打_Java实用教程:运算符
- Spring 的事务传播机制
- 聊聊Linux2038年问题
- 使用YYLabel编写直播间消息样式
- 数字转换为汉语中人民币的大写
- gc java_java内存管理以及GC
- 每日分享,一个不错的数据分析实战案例【数据分析可视化】MySQL+Python
- Vue提示 : Named Route ‘test‘ has a default child route. When navigating to this named route (:to=“{nam
- linux下的串口编程
- 接口获取行政区划代码_全国省市县行政区划分
- 连接mysql报错Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zon
热门文章
- csgo控制台所有代码飞天_CSGO飞天穿墙指令noclip设置移动速度,及卡住不动解决方法...
- 【软件工具使用】Ubuntu下高效工作工具使用(持续更新)
- 51单片机 - 红外遥控时钟
- PMP-项目风险管理
- rm -rf 真是删库跑路的一把好手
- 听说你要删库跑路了?这篇Linux脚本请收好
- 抽样分布的形式与原有总体的分布和样本容量n的大小有关
- taobao.trades.sold.increment.get( 淘宝店铺订单交易数据接口,淘宝店铺订单解密接口,淘宝店铺订单解密提额接口)代码对接教程
- MyEclipse豆沙绿颜色设置
- Idea设置豆沙绿(保护你的眼不瞎的密码)