看 如何用python爬取歌曲热门评论!

最近学了一手爬虫,于是想到用来爬一爬网友们各种文采飞扬,奇葩有趣的评论。
直接上代码。

import requests

# 引用requests模块

url = 'https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg'

for i in range(11):

    params = {

'g_tk':'5381',

'loginUin':'0', 

'hostUin':'0',

'format':'json',

'inCharset':'utf8',

'outCharset':'GB2312',

'notice':'0',

'platform':'yqq.json',

'needNewCode':'0',

'cid':'205360772',

'reqtype':'2',

'biztype':'1',

'topid':'102065756',

'cmd':'6',

'needmusiccrit':'0',

'pagenum':str(i),

'pagesize':'15',

'lasthotcommentid':'song_102065756_3202544866_44059185',

'domain':'qq.com',

'ct':'24',

'cv':'10101010' 

}

res_comments = requests.get(url,params=params)

json_comments = res_comments.json()

list_comments = json_comments['comment']['commentlist']

for comment in list_comments:
	print('--------------------------------')
    print(comment['rootcommentcontent'])

print('-----------------------------------')

当然不同的歌曲需要大家自己去修改params,
在这里插入图片描述
如图在Query String Parameters栏里直接复制粘贴过来,如何做一点点修改即可。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

弈鸣coding

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值