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,爬取,网易云
0
投稿
猜你喜欢
Go语言defer与return执行的先后顺序详解
2024-05-22 10:29:43
CSS灵活运行注释带来的益处
2008-04-21 13:51:00
ERROR CODE: 1175 YOU ARE USING SAFE UPDATE MODE AN
2024-01-17 21:57:50
Python爬虫实现爬取百度百科词条功能实例
2021-01-09 06:23:30
php事务处理实例详解
2024-05-13 09:25:30
利用ASP发送和接收XML数据的处理方法
2009-02-02 08:57:00
简单了解python的内存管理机制
2021-10-03 18:13:11
Python数据分析Pandas Dataframe排序操作
2022-06-28 07:44:11
和“登录”有关的事儿
2009-07-10 17:37:00
mysql unsigned 用法及相减出现补数溢出解决方法
2024-01-22 19:26:53
Python将QQ聊天记录生成词云的示例代码
2022-03-06 03:20:47
Pandas数据分析之pandas数据透视表和交叉表
2021-01-18 05:43:45
JS实现选项卡实例详解
2024-04-19 10:43:37
python编写网页爬虫脚本并实现APScheduler调度
2021-07-07 19:23:09
python3使用requests模块爬取页面内容的实战演练
2022-01-08 18:26:57
jquery获取复选框被选中的值
2024-04-22 13:05:24
详解在OpenCV中如何使用图像像素
2022-05-04 16:05:08
在python3.64中安装pyinstaller库的方法步骤
2022-08-12 10:27:05
Flask的图形化管理界面搭建框架Flask-Admin的使用教程
2023-03-18 07:14:03
Python安装与基本数据类型教程详解
2022-04-18 18:44:59