回答
以下是评论区自动寻找意向客户的脚本,支持抖音、小红书、快手等平台:
// 文档地址 https://docs.hamibot.com/
/**
* 评论区意向客户挖掘脚本
* 自动扫描评论区,识别潜在意向客户并记录
*/
// ==================== 配置 ====================
var CONFIG = {
// 目标平台:douyin/xiaohongshu/kuaishou
platform: "douyin",
// 意向关键词(匹配即标记为意向客户)
intentKeywords: [
"多少钱", "怎么买", "哪里买", "链接", "怎么卖",
"价格", "优惠", "便宜", "团购", "下单", "购买",
"想要", "想买", "求购", "怎么联系", "私聊",
"怎么加入", "怎么代理", "怎么做", "带带我",
"求推荐", "求分享", "求链接", "怎么操作"
],
// 排除关键词(水军/广告)
excludeKeywords: [
"点赞", "关注", "互粉", "互赞", "已赞", "已关注",
"沙发", "前排", "第一", "火钳刘明", "占位",
"666", "牛", "厉害", "好看", "爱了"
],
// 扫描设置
maxScrollCount: 50, // 最大滚动次数
scrollDelay: 1500, // 滚动间隔(毫秒)
commentWaitTime: 500, // 等待评论加载时间
// 输出设置
saveToFile: true, // 保存到文件
filePath: "/sdcard/意向客户_" + dateFormat(new Date(), "yyyyMMdd_HHmmss") + ".txt",
// 调试
debug: true
};
// ==================== 状态 ====================
var STATE = {
processedComments: [], // 已处理的评论(去重)
intentCustomers: [], // 意向客户列表
scrollCount: 0,
startTime: new Date()
};
// ==================== 工具函数 ====================
function log(msg) {
var time = dateFormat(new Date(), "HH:mm:ss");
var line = "[" + time + "] " + msg;
console.log(line);
if (CONFIG.debug) {
toast(line);
}
}
function dateFormat(date, fmt) {
var o = {
"M+": date.getMonth() + 1,
"d+": date.getDate(),
"H+": date.getHours(),
"m+": date.getMinutes(),
"s+": date.getSeconds()
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}
// 检查文本是否包含关键词
function containsKeyword(text, keywords) {
if (!text) return false;
text = text.toLowerCase();
for (var i = 0; i < keywords.length; i++) {
if (text.indexOf(keywords[i].toLowerCase()) >= 0) {
return keywords[i];
}
}
return false;
}
// 保存结果到文件
function saveResults() {
if (!CONFIG.saveToFile || STATE.intentCustomers.length == 0) return;
var content = "========== 意向客户报告 ==========\n";
content += "采集时间: " + dateFormat(STATE.startTime, "yyyy-MM-dd HH:mm:ss") + "\n";
content += "平台: " + CONFIG.platform + "\n";
content += "扫描评论数: " + STATE.processedComments.length + "\n";
content += "意向客户数: " + STATE.intentCustomers.length + "\n";
content += "================================\n\n";
for (var i = 0; i < STATE.intentCustomers.length; i++) {
var c = STATE.intentCustomers[i];
content += "【客户 " + (i + 1) + "】\n";
content += "昵称: " + c.nickname + "\n";
content += "匹配关键词: " + c.matchedKeyword + "\n";
content += "评论内容: " + c.comment + "\n";
content += "时间: " + dateFormat(c.time, "HH:mm:ss") + "\n";
content += "--------------------------------\n";
}
files.write(CONFIG.filePath, content);
log("结果已保存: " + CONFIG.filePath);
}
// ==================== 平台适配 ====================
// 获取当前平台的选择器配置
function getPlatformConfig() {
var configs = {
douyin: {
commentListId: "comment_list",
commentItemClass: "android.widget.FrameLayout",
nicknameId: "tv_nickname",
contentId: "tv_content",
descContains: "评论"
},
xiaohongshu: {
commentListId: "comment_recycler_view",
commentItemClass: "android.view.ViewGroup",
nicknameId: "nickname",
contentId: "content",
descContains: "评论"
},
kuaishou: {
commentListId: "comment_list_view",
commentItemClass: "android.widget.LinearLayout",
nicknameId: "user_name",
contentId: "comment_text",
descContains: "评论"
}
};
return configs[CONFIG.platform] || configs.douyin;
}
// ==================== 核心功能 ====================
// 提取评论信息
function extractComment(widget, pc) {
var result = {
nickname: "",
comment: "",
matchedKeyword: "",
isIntent: false,
isExclude: false
};
// 尝试多种方式获取昵称
var nicknameView = widget.findOne(id(pc.nicknameId));
if (!nicknameView) {
nicknameView = widget.findOne(className("TextView").depth(8));
}
if (nicknameView) {
result.nickname = nicknameView.text() || "";
}
// 尝试多种方式获取评论内容
var contentView = widget.findOne(id(pc.contentId));
if (!contentView) {
// 抖音:直接子元素中的 TextView
var texts = widget.find(className("TextView"));
if (texts && texts.size() > 1) {
contentView = texts.get(1);
}
}
if (contentView) {
result.comment = contentView.text() || "";
}
// 如果没有获取到内容,尝试获取所有文本
if (!result.comment) {
var allTexts = widget.find(className("TextView"));
if (allTexts && allTexts.size() > 0) {
var combined = "";
for (var i = 0; i < allTexts.size(); i++) {
var t = allTexts.get(i).text();
if (t) combined += t + " ";
}
result.comment = combined.trim();
}
}
// 去重检查
var uniqueKey = result.nickname + ":" + result.comment;
if (STATE.processedComments.indexOf(uniqueKey) >= 0) {
return null; // 已处理过
}
STATE.processedComments.push(uniqueKey);
// 意向分析
var matchedIntent = containsKeyword(result.comment, CONFIG.intentKeywords);
var matchedExclude = containsKeyword(result.comment, CONFIG.excludeKeywords);
result.isExclude = matchedExclude !== false;
result.isIntent = matchedIntent !== false && !result.isExclude;
result.matchedKeyword = matchedIntent || "";
return result;
}
// 扫描当前屏幕的评论
function scanCurrentScreen(pc) {
var found = 0;
// 查找评论列表容器
var listContainer = id(pc.commentListId).findOne(1000);
if (!listContainer) {
// 备用方案:通过描述或类名查找
listContainer = descContains(pc.descContains).findOne(1000);
}
// 获取所有评论项
var items = className(pc.commentItemClass).find();
if (!items || items.size() == 0) {
// 备用:尝试通用查找
items = className("android.view.ViewGroup").depth(10).find();
}
log("当前屏幕找到 " + (items ? items.size() : 0) + " 个元素");
if (!items) return 0;
for (var i = 0; i < items.size(); i++) {
var item = items.get(i);
var comment = extractComment(item, pc);
if (!comment) continue; // 重复或无效
found++;
// 显示处理信息
if (comment.isIntent) {
log("🎯 意向客户: " + comment.nickname);
log(" 关键词: " + comment.matchedKeyword);
log(" 内容: " + comment.comment.substring(0, 30));
STATE.intentCustomers.push({
nickname: comment.nickname,
comment: comment.comment,
matchedKeyword: comment.matchedKeyword,
time: new Date()
});
// 高亮标记(点击一下)
try {
var bounds = item.bounds();
if (bounds) {
// 绘制标记(需要悬浮窗权限)
showMark(bounds.centerX(), bounds.centerY());
}
} catch (e) {}
} else if (comment.isExclude) {
// 排除的评论,静默处理
} else {
// 普通评论
if (CONFIG.debug && found <= 3) {
log("普通: " + comment.nickname + " - " + comment.comment.substring(0, 20));
}
}
}
return found;
}
// 显示标记(需要悬浮窗权限)
function showMark(x, y) {
// 简化版:用 toast 提示
toast("🎯 发现意向客户!");
}
// 滚动加载更多
function scrollComments() {
var pc = getPlatformConfig();
// 查找可滚动区域
var scrollable = className("androidx.recyclerview.widget.RecyclerView").findOne();
if (!scrollable) {
scrollable = className("android.widget.ListView").findOne();
}
if (!scrollable) {
scrollable = scrollable ? scrollable : id(pc.commentListId).findOne();
}
if (scrollable) {
// 向下滚动
scrollable.scrollDown();
sleep(CONFIG.scrollDelay);
return true;
}
// 备用:手势滑动
var width = device.width;
var height = device.height;
swipe(width / 2, height * 0.7, width / 2, height * 0.3, 500);
sleep(CONFIG.scrollDelay);
return true;
}
// ==================== 主流程 ====================
function main() {
log("========== 评论区意向客户挖掘启动 ==========");
log("平台: " + CONFIG.platform);
log("目标关键词: " + CONFIG.intentKeywords.length + " 个");
// 请求权限
if (!requestScreenCapture()) {
log("需要截图权限");
}
var pc = getPlatformConfig();
// 主循环
while (STATE.scrollCount < CONFIG.maxScrollCount) {
STATE.scrollCount++;
log("第 " + STATE.scrollCount + " 屏扫描...");
// 扫描当前屏幕
var found = scanCurrentScreen(pc);
log("处理 " + found + " 条评论,累计意向: " + STATE.intentCustomers.length);
// 滚动下一屏
if (STATE.scrollCount < CONFIG.maxScrollCount) {
scrollComments();
}
// 每10屏保存一次
if (STATE.scrollCount % 10 == 0) {
saveResults();
}
}
// 结束保存
saveResults();
log("========== 扫描完成 ==========");
log("总评论: " + STATE.processedComments.length);
log("意向客户: " + STATE.intentCustomers.length);
// 显示结果摘要
var summary = "找到 " + STATE.intentCustomers.length + " 个意向客户\n";
for (var i = 0; i < Math.min(5, STATE.intentCustomers.length); i++) {
var c = STATE.intentCustomers[i];
summary += (i + 1) + ". " + c.nickname + " (" + c.matchedKeyword + ")\n";
}
alert("采集完成", summary);
}
// ==================== 启动 ====================
// 先手动打开目标视频的评论页面
log("请手动打开目标视频的评论页面");
log("3秒后开始...");
sleep(3000);
main();
使用步骤
| 步骤 | 操作 |
|---|---|
| 1 | 手动打开抖音/小红书/快手视频 |
| 2 | 展开评论区 |
| 3 | 运行脚本 |
| 4 | 自动滚动扫描,标记意向客户 |
输出结果
========== 意向客户报告 ==========
采集时间: 2024-01-15 14:32:18
平台: douyin
扫描评论数: 127
意向客户数: 8
================================
【客户 1】
昵称: 小明想赚钱
匹配关键词: 怎么代理
评论内容: 这个怎么做代理啊?带带我
时间: 14:32:05
--------------------------------
...
自定义配置
修改 CONFIG 中的:
intentKeywords:你的业务相关关键词platform:目标平台maxScrollCount:扫描深度
ℹ️ 内容由 AI 生成,可能不准确,请注意核实