Python简单实现自动评论、自动点赞、自动关注脚本
一些哔哔:
今天的这个脚本,是一个别人发的外包,交互界面的代码就不在这里说了,但是可以分享下自动评论、自动点赞、自动关注、采集评论和视频的数据是如何实现的
开发环境
python 3.8 运行代码
pycharm 2021.2 辅助敲代码
requests 第三方模块
原理:
模拟客户端,向服务器发送请求
代码实现
1. 请求伪装
###想要学习Python?Python学习交流群:660193417 满足你的需求,资料都已经上传群文件,可以自行下载!###
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': 'www.ks.com',
'Origin': 'https://www.ks.com',
'Referer': 'https://www.ks.com/search/video?searchKey=%E9%BB%91%E4%B8%9D',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36',
}
self.url = 'https://www.ks.com/graphql'
2. 获取搜索内容的方法
###想要学习Python?Python学习交流群:660193417 满足你的需求,资料都已经上传群文件,可以自行下载!###
def get_search(self, keyword, pcursor):
"""
:param keyword: 关键词
:param pcursor: 页码
:return: 搜索作品
"""
json = {
'operationName': "visionSearchPhoto",
'query': "fragment photoContent on PhotoEntity {\n id\n duration\n caption\n likeCount\n viewCount\n realLikeCount\n coverUrl\n photoUrl\n photoH265Url\n manifest\n manifestH265\n videoResource\n coverUrls {\n url\n __typename\n }\n timestamp \n animatedCoverUrl\n distance\n videoRatio\n liked\n stereoType\n profileUserTopPhoto\n __typename\n}\n\nfragment feedContent on Feed {\n type\n author {\n id\n name\n headerUrl\n following\n headerUrls {\n url\n __typename\n }\n __typename\n }\n photo {\n ...photoContent\n __typename\n }\n canAddComment\n llsid\n status\n currentPcursor\n __typename\n}\n\nquery visionSearchPhoto($keyword: String, $pcursor: String, $searchSessionId: String, $page: String, $webPageArea: String) {\n visionSearchPhoto(keyword: $keyword, pcursor: $pcursor, searchSessionId: $searchSessionId, page: $page, webPageArea: $webPageArea) {\n result\n llsid\n webPageArea\n feeds {\n ...feedContent\n __typename\n }\n searchSessionId\n pcursor\n aladdinBanner {\n imgUrl\n link\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)
return json_data
3. 获取作品评论
###想要学习Python?Python学习交流群:660193417 满足你的需求,资料都已经上传群文件,可以自行下载!###
def get_comments(self, photoId, pcursor):
"""
:param photoId: 作品id
:param pcursor: 页码
:return: 评论内容
"""
json = {
'operationName': "commentListQuery",
'query': "query commentListQuery($photoId: String, $pcursor: String) { visionCommentList(photoId: $photoId, pcursor: $pcursor) {\n commentCount\n rootComments {\n commentId\n authorId\n authorName\n content\n headurl\n timestamp\n likedCount\n realLikedCount\n liked\n status\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 replyToUserName\n replyTo\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)
return json_data
4. 自动评论
def post_comment(self, content, photoAuthorId, photoId):
"""
:param content: 评论内容
:param photoAuthorId: 该作品的作者id
:param photoId: 作品id
:return: 有没有成功
"""
json = {
'operationName': "visionAddComment",
'query': "mutation visionAddComment($photoId: String, $photoAuthorId: String, $content: String, $replyToCommentId: ID, $replyTo: ID, $expTag: String) { (photoId: $photoId, photoAuthorId: $photoAuthorId, content: $content, replyToCommentId: $replyToCommentId, replyTo: $replyTo, expTag: $expTag) {\n result\n commentId\n content\n timestamp\n status\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)
return json_data
5. 点赞操作
def is_like(self, photoId, photoAuthorId):
"""
:param photoId: 作品id
:param photoAuthorId: 该作品的作者id
:return: 有没有成功
"""
json = {
'operationName': "visionVideoLike",
'query': "mutation visionVideoLike($photoId: String, $photoAuthorId: String, $cancel: Int, $expTag: String) {\n visionVideoLike(photoId: $photoId, photoAuthorId: $photoAuthorId, cancel: $cancel, expTag: $expTag) {\n result\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)
return json_data
6. 关注操作
def is_follow(self, touid):
"""
:param touid: 用户id
:return:
"""
json = {
'operationName': "visionFollow",
'query': "mutation visionFollow($touid: String, $ftype: Int, $followSource: Int, $expTag: String) {\n visionFollow(touid: $touid, ftype: $ftype, followSource: $followSource, expTag: $expTag) {\n followStatus\n hostName\n error_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)
return json_data
7. 获取创作者信息
def get_userInfo(self, userId):
"""
:param userId: 用户ID
:return: 用户信息
"""
json = {
'operationName': "visionProfile",
'query': "query visionProfile($userId: String) {\n visionProfile(userId: $userId) {\n hostName\n userProfile {\n ownerCount {\n fan\n photo\n follow\n photo_public\n __typename\n }\n profile {\n gender\n user_name\n user_id\n headurl\n user_text\n user_profile_bg_url\n __typename\n }\n isFollowing\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)
return json_data
8. 获取创作者视频
def get_video(self, userId, pcursor):
"""
:param userId: 用户id
:param pcursor: 页码
:return: 作品
"""
json = {
'operationName': "visionProfilePhotoList",
'query': "fragment photoContent on PhotoEntity {\n duration\n caption\n likeCount\n viewCount\n realLikeCount\n coverUrl\n photoUrl\n photoH265Url\n manifest\n manifestH265\n videoResource\n coverUrls {\n url\n __typename\n }\n timestamp\n expTag\n animatedCoverUrl\n distance\n videoRatio\n liked\n stereoType\n profileUserTopPhoto\n __typename\n}\n\nfragment feedContent on Feed {\n type\n author {\n id\n name\n headerUrl\n following\n headerUrls {\n url\n __typename\n }\n __typename\n }\n photo {\n ...photoContent\n __typename\n }\n canAddComment\n llsid\n status\n currentPcursor\n __typename\n}\n\nquery visionProfilePhotoList($pcursor: String, $userId: String, $page: String, $webPageArea: String) {\n visionProfilePhotoList(pcursor: $pcursor, userId: $userId, page: $page, webPageArea: $webPageArea) {\n result\n llsid\n webPageArea\n feeds {\n ...feedContent\n __typename\n }\n hostName\n pcursor\n __typename\n }\n}\n",
'variables': {'userId': userId, 'pcursor': pcursor, 'page': "profile"}
}
response = requests.post(url=self.url, json=json, headers=self.headers)
json_data = response.json()
print(json_data)
return json_data
9. 调用函数
if __name__ == '__main__':
kuaishou = KuaiShou()
# 获取评论
kuaishou.get_comments('3xzry7secwhunai', '')
# 发布评论
kuaishou.post_comment('爱你', '3xgz9zaku7hig96', '3xydesqbvtrvcuq')
# 点赞
kuaishou.is_like('3xydesqbvtrvcuq', '3xgz9zaku7hig96')
# 关注
kuaishou.is_follow('3xxhfqquuachnje')
# 创作者信息
kuaishou.get_userInfo('3xxhfqquuachnje')
# 获取创作者作品
kuaishou.get_video('3xxhfqquuachnje', '')
Python简单实现自动评论、自动点赞、自动关注脚本的更多相关文章
- nodejs什么值得买自动签到自动评论定时任务
本项目是基于nodejs开发,实现的功能是,什么值得买自动签到,自动评论功能,自动发邮件,支持多人多账号运行 目的是为了,解放双手,轻松获取什么值得买的经验和积分,得到更高的等级,从而突破很会员等级限 ...
- python登录csdn并自动评论下载资源脚本
功能 1.自动登录csdn 2.查找未评论的资源并自动评论 用到的库 1.python自带的requests,获取以及发送网页数据 2.python自带的time,用作休眠,csdn资源一段时间内只允 ...
- ipython, 一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数
一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数. 若用的是fish s ...
- 2.如何实现使用VBS脚本程序对直播间自动评论
前言:本文使用的是VBS脚本,实现了对繁星直播自动登录,自动进入房间并且自动评论. 前提准备:把需要刷的评论放到mysql中,再使用vbs读出评论 -------------------------- ...
- python+splinter实现12306网站刷票并自动购票流程
python+splinter实现12306网站刷票并自动购票流程 通过python+splinter,实现在12306网站刷票并自动购票流程(无法自动识别验证码). 此类程序只是提高了12306网站 ...
- 一个简单的执行程序的GNU automake自动生成Makefile的方法及案例
一个简单的执行程序的GNU automake自动生成Makefile的方法及案例 在GNU的世界里,存在Automake这样的工具进行自动生成Makefile文件,automake是由Perl语言编写 ...
- Web自动化框架之五一套完整demo的点点滴滴(excel功能案例参数化+业务功能分层设计+mysql数据存储封装+截图+日志+测试报告+对接缺陷管理系统+自动编译部署环境+自动验证false、error案例)
标题很大,想说的很多,不知道从那开始~~直接步入正题吧 个人也是由于公司的人员的现状和项目的特殊情况,今年年中后开始折腾web自动化这块:整这个原因很简单,就是想能让自己偷点懒.也让减轻一点同事的苦力 ...
- struts2各个功能详解(1)----参数自动封装和类型自动转换
struts2里面的各个功能,现在确实都不清楚,完全属于新学! 通过前面的例子,有时就会疑问,这些jsp中的数据信息是怎么传送给action的?例如: <form action = " ...
- 定时自动从FTP服务器取数据脚本
环境需求:某些情况下经常需要向FTP服务器取文件,可以用定时任务执行简单脚本自动去取相应文件. 一般用法: ~]# ftp IP地址 端口 //ftp命令可以通过yum install ftp方式 ...
随机推荐
- 2021.12.07 [TJOI2013]最长上升子序列(Treap+DP)
2021.12.07 [TJOI2013]最长上升子序列(Treap+DP) https://www.luogu.com.cn/problem/P4309 题意: 给定一个序列,初始为空.现在我们将1 ...
- Java函数的学习
函数的定义 - 定义的位置:定义在类的内部 - 组成部分: 函数修饰符 类型 函数名(形式参数){ 局部变量: 注释: 函数体: } 函数的调用 - 调用函数时使用 : `函数名():` - 函数在执 ...
- Amazing!巧用 CSS 视差实现酷炫交互动效
本文将介绍利用 CSS 实现滚动视差效果的一个小技巧,并且,利用这个技巧来制作一些有意思的交互特效. 关于使用 CSS 实现滚动视差效果,在之前有一篇文章详细描述过具体方案 - CSS 实现视差效果, ...
- 项目依赖模块解决、二次封装Response、后台数据库配置、user模块user表设计、前台创建及配置
今日内容概要 二次封装Response 后台数据库配置 user模块user表设计 前台创建及配置 内容详细 补充--项目依赖模块 # 导出项目依赖模块和安装项目依赖模块 第三方模块--->导出 ...
- 【虚拟机】VMware-VMware Tool安装
1.安装 在VMware Workstation主界面点击菜单"虚拟机".会弹出提示框,点击是. 保持网络状态,等待后台下载,下载后会出现一个压缩包(如果没有出现压缩包请点击这里查 ...
- C++逆向 可变参数Hook
目录 C++逆向 可变参数Hook 0x00 前言: 0x01 C++可变参数: 可变参数简介 可变参数代码实战 0x02 逆向分析C++可变参数原理 0x03 printf Hook实战 Pwn菜鸡 ...
- 使用aspnetcore前后端分离开发,你一定要知道这个
前言 用过Vue单页面应用开发的,一定都知道Vue-router这个路由组件,它支持hash和history两种模式. HTML5 History 模式 vue-router 默认 hash 模式 - ...
- .NET桌面程序集成Web网页开发的多种解决方案
系列目录 [已更新最新开发文章,点击查看详细] B/S架构的Web程序几乎占据了应用软件的绝大多数市场,但是C/S架构的WinForm.WPF客户端程序依然具有很实用的价值,如设计类软件 Au ...
- Matlab学习笔记 绘图
1.二维曲线(1)plot函数①plot函数的基本用法:plot(x,y),其中x和y分别用于存储x坐标和y坐标数据. >>x=[1,2,3]; >>y=[4,5,6]; &g ...
- MyBatisPlus实现分页和查询操作就这么简单
<SpringBoot整合MybatisPlus基本的增删改查,保姆级教程>在这篇文章中,我们详细介绍了分页的具体实现方法.但是,在日常的开发中还需要搜索功能的.下面让我们一起动起手来,实 ...