获取快手评论

import requests
import csv
#保存数据
f=open('快手评论19.txt',mode='a',encoding='utf-8',newline='')
csv_writer=csv.writer(f)
csv_writer.writerow(['comment'])
headers={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.81',
    #did=web_bf55ab6c2d565d791b00f378cf0ad245; didv=1694483268622; kpf=PC_WEB; clientid=3; kpn=KUAISHOU_VISION
    #did=web_bf55ab6c2d565d791b00f378cf0ad245; didv=1694483268622; kpf=PC_WEB; clientid=3; kpn=KUAISHOU_VISION
    'cookie':'did=web_bf55ab6c2d565d791b00f378cf0ad245; didv=1694483268622; kpf=PC_WEB; clientid=3; userId=132516133; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABS_riA4fyZbFAAVBR2tVwS8FvZ9e30oKuGLntt5dA6-sjjQcRmK4VFCmPr9P4wQbZecl4TWVwomrra9KpNsszw3wVuAm4VHKxwd66sCntEdLQl4kpC0rHp82deZLl7Z9_oNb7yltyjZuIQPTRObPjOJAqhLkBNt4N20ktDMHhhzf310iEtErd_1mMPWDNNgpHt6AU7XyCSKjGzDbKh8Ub4hoS7YoRGiN2PM_7zCD1Dj9m5oYoIiDEcxyqnYA3b7ZyFHSSp9EBaaGkrdMCn82_7tP9mK3PsCgFMAE; kuaishou.server.web_ph=25ec7cc74dc4e28961b584395bab01cea7cc; kpn=KUAISHOU_VISION',
              #https://www.kuaishou.com/short-video/3xj3qiksk3ht8pe?authorId=3xyfnq5qmwtw7iu&streamSource=search&searchKey=%E4%B8%89%E8%83%8E%E5%AD%95%E5%A6%88&area=searchxxnull
    #https://www.kuaishou.com/short-video/3xvy6njb6u3jvqs?authorId=3xyrd52b4kqan7k&streamSource=samecity&area=nearbyxxnull
    'Referer':'https://www.kuaishou.com/short-video/3xttih7au72uz7w?authorId=3xv5fuk2yx92b5s&streamSource=search&area=searchxxnull&searchKey=%E6%80%80%E5%AD%95%E4%B8%89%E5%8F%B0',
    'Host':'www.kuaishou.com',
}

url1=input('输入想要获取的视频链接:')
a=url1.split("/")[4]
b=a.split("?")[0]


pcursor=[]
for i in range(1,50):
    json={
        'operationName': 'commentListQuery',
        'query':'query commentListQuery($photoId: String, $pcursor: String) {\n  visionCommentList(photoId: $photoId, pcursor: $pcursor) {\n    commentCount\n    pcursor\n    rootComments {\n      commentId\n      authorId\n      authorName\n      content\n      headurl\n      timestamp\n      likedCount\n      realLikedCount\n      liked\n      status\n      authorLiked\n      subCommentCount\n      subCommentsPcursor\n      subComments {\n        commentId\n        authorId\n        authorName\n        content\n        headurl\n        timestamp\n        likedCount\n        realLikedCount\n        liked\n        status\n        authorLiked\n        replyToUserName\n        replyTo\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n}\n',
        'variables': {'photoId': f"{b}", 'pcursor': f"{pcursor}"}#photoId是视频号
    }
    url='https://www.kuaishou.com/graphql'
    response =requests.post(url=url, json=json,headers=headers)
    json_data=response.json()
    feeds=json_data['data']['visionCommentList']['rootComments']
    pcursor=json_data['data']['visionCommentList']['pcursor']
    for data in feeds:
        comment=data['content']
        print(comment)
        csv_writer.writerow([comment])

请求头要根据自己的实际情况填写。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值