Python实现简单自动评论自动点赞自动关注脚本_第1页
Python实现简单自动评论自动点赞自动关注脚本_第2页
Python实现简单自动评论自动点赞自动关注脚本_第3页
Python实现简单自动评论自动点赞自动关注脚本_第4页
Python实现简单自动评论自动点赞自动关注脚本_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第Python实现简单自动评论自动点赞自动关注脚本目录前言开发环境原理:代码实现1.请求伪装2.获取搜索内容的方法3.获取作品评论4.自动评论5.点赞操作6.关注操作7.获取创作者信息8.获取创作者视频9.调用函数

前言

今天的这个脚本,是一个别人发的外包,交互界面的代码就不在这里说了,但是可以分享下自动评论、自动点赞、自动关注、采集评论和视频的数据是如何实现的

开发环境

python3.8运行代码

pycharm2025.2辅助敲代码

requests第三方模块

原理:

模拟客户端,向服务器发送请求

代码实现

1.请求伪装

def__init__(self):

self.headers={

'content-type':'application/json',

'Cookie':'kpf=PC_WEB;kpn=KUAISHOU_VISION;clientid=3;did=web_ea128125517a46bd491ae9ccb255e242;client_key=65890b29;didv=1646739254078;_bl_uid=pCldq3L00L61qCzj6fytnk2wmhz5;userId=270932146;kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABH2BHihXp4liEYWMBFv9aguyfs8BsbINQIWqgoDw0SimMkpXwM7PKpKdJcZbU12QOyeKFaG4unV5EUkkEswL0HnA8_A9z2ujLlKN__gRsxU2B5kIYgirTDPiVJ3uPN1sU9mqvog3auoNJxDdbKjVeFNK1wQ5HTM_yUvYvmWOx9iC8IKcvnmo9YnG_J9ske-t-wiCWMgSCA25HN6MRqCMxuhoSnIqSq99L0mk4jolsseGdcwiNIiC8rjheuewIA1Bk3LwkNIYikU2zobcuvgAiBbMnBuDixygFMAE;kuaishou.server.web_ph=55c7e6b2033ea94a3447ea98082642cd6f1a',

'Host':'',

'Origin':'',

'Referer':'/search/videosearchKey=%E9%BB%91%E4%B8%9D',

'User-Agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/101.0.4951.67Safari/537.36',

self.url='/graphql'

2.获取搜索内容的方法

defget_search(self,keyword,pcursor):

:paramkeyword:关键词

:parampcursor:页码

:return:搜索作品

json={

'operationName':"visionSearchPhoto",

'query':"fragmentphotoContentonPhotoEntity{\nid\nduration\ncaption\nlikeCount\nviewCount\nrealLikeCount\ncoverUrl\nphotoUrl\nphotoH265Url\nmanifest\nmanifestH265\nvideoResource\ncoverUrls{\nurl\n__typename\n}\ntimestamp\nanimatedCoverUrl\ndistance\nvideoRatio\nliked\nstereoType\nprofileUserTopPhoto\n__typename\n}\n\nfragmentfeedContentonFeed{\ntype\nauthor{\nid\nname\nheaderUrl\nfollowing\nheaderUrls{\nurl\n__typename\n}\n__typename\n}\nphoto{\n...photoContent\n__typename\n}\ncanAddComment\nllsid\nstatus\ncurrentPcursor\n__typename\n}\n\nqueryvisionSearchPhoto($keyword:String,$pcursor:String,$searchSessionId:String,$page:String,$webPageArea:String){\nvisionSearchPhoto(keyword:$keyword,pcursor:$pcursor,searchSessionId:$searchSessionId,page:$page,webPageArea:$webPageArea){\nresult\nllsid\nwebPageArea\nfeeds{\n...feedContent\n__typename\n}\nsearchSessionId\npcursor\naladdinBanner{\nimgUrl\nlink\n__typename\n}\n__typename\n}\n}\n",

'variables':{'keyword':keyword,'pcursor':pcursor,'page':"search"}

response=requests.post(url=self.url,json=json,headers=self.headers)

json_data=response.json()

print(json_data)

returnjson_data

3.获取作品评论

defget_comments(self,photoId,pcursor):

:paramphotoId:作品id

:parampcursor:页码

:return:评论内容

json={

'operationName':"commentListQuery",

'query':"querycommentListQuery($photoId:String,$pcursor:String){visionCommentList(photoId:$photoId,pcursor:$pcursor){\ncommentCount\nrootComments{\ncommentId\nauthorId\nauthorName\ncontent\nheadurl\ntimestamp\nlikedCount\nrealLikedCount\nliked\nstatus\nsubCommentCount\nsubCommentsPcursor\nsubComments{\ncommentId\nauthorId\nauthorName\ncontent\nheadurl\ntimestamp\nlikedCount\nrealLikedCount\nliked\nstatus\nreplyToUserName\nreplyTo\n__typename\n}\n__typename\n}\n__typename\n}\n}\n",

'variables':{'photoId':photoId,'pcursor':pcursor}

response=requests.post(url=self.url,json=json,headers=self.headers)

json_data=response.json()

print(json_data)

returnjson_data

4.自动评论

defpost_comment(self,content,photoAuthorId,photoId):

:paramcontent:评论内容

:paramphotoAuthorId:该作品的作者id

:paramphotoId:作品id

:return:有没有成功

json={

'operationName':"visionAddComment",

'query':"mutationvisionAddComment($photoId:String,$photoAuthorId:String,$content:String,$replyToCommentId:ID,$replyTo:ID,$expTag:String){(photoId:$photoId,photoAuthorId:$photoAuthorId,content:$content,replyToCommentId:$replyToCommentId,replyTo:$replyTo,expTag:$expTag){\nresult\ncommentId\ncontent\ntimestamp\nstatus\n__typename\n}\n}\n",

'variables':{

'content':content,

'expTag':"1_a/2005158523885162817_xpcwebsearchxxnull0",

'photoAuthorId':photoAuthorId,

'photoId':photoId

response=requests.post(url=self.url,json=json,headers=self.headers)

json_data=response.json()

print(json_data)

returnjson_data

5.点赞操作

defis_like(self,photoId,photoAuthorId):

:paramphotoId:作品id

:paramphotoAuthorId:该作品的作者id

:return:有没有成功

json={

'operationName':"visionVideoLike",

'query':"mutationvisionVideoLike($photoId:String,$photoAuthorId:String,$cancel:Int,$expTag:String){\nvisionVideoLike(photoId:$photoId,photoAuthorId:$photoAuthorId,cancel:$cancel,expTag:$expTag){\nresult\n__typename\n}\n}",

'variables':{

'cancel':0,

'expTag':"1_a/2005158523885162817_xpcwebsearchxxnull0",

'photoAuthorId':photoAuthorId,

'photoId':photoId

response=requests.post(url=self.url,json=json,headers=self.headers)

json_data=response.json()

print(json_data)

returnjson_data

6.关注操作

defis_follow(self,touid):

:paramtouid:用户id

:return:

json={

'operationName':"visionFollow",

'query':"mutationvisionFollow($touid:String,$ftype:Int,$followSource:Int,$expTag:String){\nvisionFollow(touid:$touid,ftype:$ftype,followSource:$followSource,expTag:$expTag){\nfollowStatus\nhostName\nerror_msg\n__typename\n}\n}\n",

'variables':{

'expTag':"1_a/2005158523885162817_xpcwebsearchxxnull0",

'followSource':3,

'ftype':1,

'touid':touid

response=requests.post(url=self.url,json=json,headers=self.headers)

json_data=response.json()

print(json_data)

returnjson_data

7.获取创作者信息

defget_userInfo(self,userId):

:paramuserId:用户ID

:return:用户信息

json={

'operationName':"visionProfile",

'query':"queryvisionProfile($userId:String){\nvisionProfile(userId:$userId){\nhostName\nuserProfile{\nownerCount{\nfan\nphoto\nfollow\nphoto_public\n__typename\n}\nprofile{\ngender\nuser_name\nuser_id\nheadurl\nuser_text\nuser_profile_bg_url\n__typename\n}\nisFollowing\n__typename\n}\n__typename\n}\n}\n",

'variables':{'userId':userId}

response=requests.post(url=self.url,json=json,headers=self.headers)

json_data=response.json()

print(json_data)

returnjson_data

8.获取创作者视频

defget_video(self,userId,pcursor):

:paramuserId:用户id

:parampcursor:页码

:return:作品

json={

'operationName':"visionProfilePhotoList",

'query':"fragmentphotoContentonPhotoEntity{\nduration\ncaption\nlikeCount\nviewCount\nrealLikeCount\ncoverUrl\nphotoUrl\nphotoH265Url\nmanifest\nmanifestH265\nvideoResource\ncoverUrls{\nurl\n__typename\n}\ntimestamp\nexpTag\nanimatedCoverUrl\ndistance\nvideoRatio\nliked\nstereoType\nprofileUserTopPhoto\n__typename\n}\n\nfragmentfeedContentonFeed{\ntype\nauthor{\nid\nname\nheaderUrl\nfollowing\nheaderUrls{\nurl\n__typename\n}\n__typename\n}\nphoto{\n...photoContent\n__typename\n}\ncanAddComment\nllsid\nstatus\ncurrentPcursor\n__typename\n}\n\nqueryvisionProfilePhotoList($pcursor:String,$userId:String,$page:String,$webPageArea:String){\nvisionProfilePhotoList(pcursor:$pcursor,userId:$userId,page:$page,webPageArea:$webPageArea){\n

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论