python爬取网易云音乐评论
作者:lijiao 时间:2021-02-23 11:23:02
本文实例为大家分享了python爬取网易云音乐评论的具体代码,供大家参考,具体内容如下
import requests
import bs4
import json
def get_hot_comments(res):
comments_json = json.loads(res.text)
hot_comments = comments_json['hotComments']
with open("hotcmments.txt", 'w', encoding = 'utf-8') as f:
for each in hot_comments:
f.write(each['user']['nickname']+':\n')
f.write(each['content']+'\n\n')
f.write("-------------------------------------\n")
def open_url(url):
rname_id = url.split('=')[1]
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
"referer": "http://music.163.com/song?id=4466775&market=baiduqk"}
params = "PWXGrRPQKqZfgF4QTEivQ9eZfrCscY2YtKA60Xw6P6kL6v4J09c/g+PNwzks+mpwUDmjDWvJ0CNfV/Vzeh0iLNIVyWZ+9wezTESdC2/lpPKgcSgFo8au3evlS5OpciLmVG7YGhEFiocZQ/ccGaFdG4WdqStjPDEIoBfzeGZJZIsixW0SG4zVhBrfgKTi0i22"
encSecKey = "61be0f8c5305c919985b294069695d2ba84746c75ed902e8157b6b595a920c57cfedf552f5c764fed37be84bfd1cce31e05eb364644930fbe6bc074747ed8e670933aef4d8b8841209c6956f4b532f8a3caadfaffb61f233a42e53dc5795183b9c6ccb30b8aa56d656466cc6523e8213560bb3e476ab95d58755f47f91cf7f53"
data ={
"params": params,
"encSecKey": encSecKey
}
target_url = "http://music.163.com/weapi/v1/resource/comments/R_SO_4_{}??csrf_token=".format(rname_id)
res = requests.post(target_url, headers = headers,data = data)
return res
def main():
#url = input("请输入您需要获取的歌曲地址:")
url = "http://music.163.com/#/song?id=4466775"
res = open_url(url)
get_hot_comments(res)
#with open("res.txt",'w', encoding = 'utf-8') as f:
# f.write(res.text)
if __name__ == "__main__":
main()
标签:python,爬取,网易云
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
奇淫技巧和西天取经
2009-08-24 12:34:00
SQL Server数据库于应用程序的关系
2010-07-26 14:21:00
使用python+whoosh实现全文检索
2021-01-04 05:29:46
微信小程序页面缩放式侧滑效果的实现代码
2023-09-02 05:21:45
![](https://img.aspxhome.com/file/2023/4/56264_0s.gif)
在python中将list分段并保存为array类型的方法
2023-11-15 10:18:00
python读写修改Excel之xlrd&xlwt&xlutils
2022-04-03 16:35:43
![](https://img.aspxhome.com/file/2023/9/94149_0s.jpg)
php下检测字符串是否是utf8编码的代码
2023-11-15 16:00:59
Python对多个sheet表进行整合实例讲解
2021-01-15 06:18:24
select @@identity的应用(得到刚插入数据的ID)
2009-09-10 11:24:00
python函数的重新定义及练习
2023-10-12 22:47:55
![](https://img.aspxhome.com/file/2023/8/63528_0s.png)
在Python中利用pickle保存变量的实例
2021-05-04 04:25:50
![](https://img.aspxhome.com/file/2023/2/68882_0s.jpg)
Python中的条件判断语句基础学习教程
2021-06-19 11:51:36
Oracle动态交叉表生成
2010-07-27 12:55:00
Python3 queue队列模块详细介绍
2023-10-03 05:10:51
Docker实践之python应用容器化
2023-06-07 03:29:43
![](https://img.aspxhome.com/file/2023/7/70187_0s.png)
了解CSS的查找匹配原理,让CSS更简洁、高效
2010-06-08 13:36:00
关于Thinkphp6的日志问题
2023-06-06 10:54:23
![](https://img.aspxhome.com/file/2023/2/55502_0s.png)
Python可视化单词统计词频统计中文分词的实现步骤
2023-10-24 17:16:49
![](https://img.aspxhome.com/file/2023/4/85164_0s.jpg)
pygame实现雷电游戏雏形开发
2021-04-14 13:52:31
![](https://img.aspxhome.com/file/2023/6/93976_0s.jpg)
PHP中PDO事务处理操作示例
2023-11-21 14:54:12