最近学了一手爬虫,于是想到用来爬一爬网友们各种文采飞扬,奇葩有趣的评论。
直接上代码。
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栏里直接复制粘贴过来,如何做一点点修改即可。