本次教程使用Python编写,无编程基础者直接复制粘贴,严格按步骤操作即可。
python -V,出现Python 3.10.11即为成功pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simplepip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simplepip install schedule -i https://pypi.tuna.tsinghua.edu.cn/simpleapi.kuaishou.com的请求,点击该请求,在右侧“Headers”->“Request Headers”中找到User-Agent、Referer,复制备用新建记事本,粘贴以下代码,保存为“kuaishou_monitor.py”(同样改后缀):
```python import requests import json import pandas as pd import time import schedule def load_cookie(): with open("kuaishou_cookie.json", "r", encoding="utf-8") as f: cookies = json.load(f) return {c['name']: c['value'] for c in cookies} COOKIES = load_cookie() HEADERS = { "User-Agent": "你刚才复制的User-Agent", "Referer": "你刚才复制的Referer" } def get_video_flow(): try: 获取作品列表公开数据(仅获取自己可见或公开作品,接口参数可调整) url = "https://api.kuaishou.com/rest/n/photo/list?pcursor=&count=20" res = requests.get(url, cookies=COOKIES, headers=HEADERS, timeout=10) res.raise_for_status() data = res.json() if data.get("result") != 1: print(f"获取失败:{data.get('error_msg')}") return videos = [] for item in data.get("feeds", []): videos.append({ "作品ID": item.get("photoId"), "作品标题": item.get("caption", "无标题")[:30], 截取前30字避免表格太长 "发布时间": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(item.get("timestamp"))), "播放量": item.get("viewCount", 0), "点赞量": item.get("likeCount", 0), "评论量": item.get("commentCount", 0), "转发量": item.get("shareCount", 0) }) 保存数据到Excel df = pd.DataFrame(videos) df.to_excel(f"快手流量数据_{time.strftime('%Y%m%d_%H%M%S')}.xlsx", index=False) print(f"流量数据已保存:快手流量数据_{time.strftime('%Y%m%d_%H%M%S')}.xlsx") except Exception as e: print(f"监控出错:{str(e)}") if __name__ == "__main__": 设置每30分钟监控一次 schedule.every(30).minutes.do(get_video_flow) get_video_flow() 首次运行立即执行 print("流量监控已启动,每30分钟保存一次数据...") while True: schedule.run_pending() time.sleep(1) ```
注意:代码中第13、14行的User-Agent和Referer必须替换成你自己复制的内容!
冷启动辅助模块主要功能是:识别发布后1小时播放量低于200的作品,模拟点击快手创作者中心的“加热建议浏览”(仅公开接口,无违规刷量,仅获取官方精准投放建议辅助人工决策)。新建记事本,粘贴以下代码,保存为“kuaishou_heat_help.py”:
```python import requests import json import time def load_cookie(): with open("kuaishou_cookie.json", "r", encoding="utf-8") as f: cookies = json.load(f) return {c['name']: c['value'] for c in cookies} COOKIES = load_cookie() HEADERS = { "User-Agent": "你刚才复制的User-Agent", "Referer": "你刚才复制的Referer" } def check_and_help_cold_start(): try: url = "https://api.kuaishou.com/rest/n/photo/list?pcursor=&count=20" res = requests.get(url, cookies=COOKIES, headers=HEADERS, timeout=10) res.raise_for_status() data = res.json() if data.get("result") != 1: print(f"获取作品失败:{data.get('error_msg')}") return current_time = time.time() for item in data.get("feeds", []): 筛选发布1小时内、播放量<200的公开/自己作品 publish_time = item.get("timestamp") if current_time - publish_time < 3600 and item.get("viewCount", 0) < 200: photo_id = item.get("photoId") caption = item.get("caption", "无标题")[:30] print(f"检测到冷启动作品:{caption}(ID:{photo_id})") 调用公开加热建议接口 help_url = f"https://api.kuaishou.com/rest/n/creator/photo/heat/suggest?photoId={photo_id}" help_res = requests.get(help_url, cookies=COOKIES, headers=HEADERS, timeout=10) help_data = help_res.json() if help_data.get("result") == 1: suggest = help_data.get("suggest", {}).get("content", "无官方加热建议") print(f"官方加热建议:{suggest}\n") else: print(f"获取加热建议失败:{help_data.get('error_msg')}\n") except Exception as e: print(f"冷启动辅助出错:{str(e)}") if __name__ == "__main__": 设置每15分钟检测一次 import schedule schedule.every(15).minutes.do(check_and_help_cold_start) check_and_help_cold_start() 首次运行立即执行 print("冷启动辅助已启动,每15分钟检测一次...") while True: schedule.run_pending() time.sleep(1) ```再次注意:同样替换第13、14行的内容!
python kuaishou_monitor.py,按回车即可启动,不要关闭命令窗口python kuaishou_heat_help.py,按回车即可启动上一篇: 跨境电商优化:这波操作让老外乖乖掏钱
易频IT社区是综合性互联网IT技术门户网站,专注分享网络技术、服务器运维、网络安全、编程开发、系统架构、云计算、大数据等行业干货,实时更新IT行业资讯、零基础教程、实战案例,为IT从业者、技术爱好者提供专业的学习交流平台。
Copyright © 2021-2026 易频IT社区. All Rights Reserved. 备案号:闽ICP备2023013482号 网站地图