|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
图片如下:
代码如下:
- # 爬取网易云音乐的热门评论
- import requests
- import json
- def get_hot_comments(res):
- comments_json = json.loads(res.text)
- hot_comments = comments_json['data']['hotComments']
- with open('hot_comments.txt', 'w', encoding='utf-8') as file:
- for each in hot_comments:
- file.write(each['content'] + '\n')
- file.write("----------------------------------------\n")
-
- def get_comments(url):
- # 传给它referer
- # 当然,有时间的话将headers头部填写完整,那样会更好一些
- headers = {
- 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
- 'referer':'http://music.163.com/'
- }
- params = 'qwlzsLiNsFKaTuA35GUvfSbubkyePTPj2UxjaTe6KGyPkHwZGR48+RklK+UytoBSpYzR1208h4cx3iuy3nAVmsWI/L2rh8m+AZQ5dJhk+CrymGZdidV5OzDOBeKpqpIWZCCo2KgCoiRdXQ7vB2xwwZ32Qw8p0f3/9n/s3CnYDvnA/d3aVb8VyjtRaSd13ilnkHkt1f+Iadh27Vp9Fw62nQ1jdH7tswHEUmCm0+daLK73JYv1dSk4CnD6OqwgAtxeDih31OE4hP1cYrT2wS+ukA=='
- encSecKey = '88a3e4f6e67fcd26e48988f1129187acfc6cfa14f873c9448c05d0fef2ed52c0825076672a8a115141b51ec15e00402b6105464871ae1bfcdd917f4d4a75093f3366a528cf655a0ac17fb9cce585e3c3e418cf8871844e78a3710a3353c53a50289fcf436a678c753a51a4d7cb45120c3d8a902a903d768d2b9ad88e6958743d'
- data = {
- "params":params,
- "encSecKey":encSecKey
- }
-
- res = requests.post(url, headers=headers, data=data)
- return res
- def main():
- url = input("请输入链接地址:(请包含http或https协议):")
- res = get_comments(url)
- get_hot_comments(res)
- if __name__=="__main__":
- main()
复制代码
|
|