下载地址:https://www.pan38.com/share.php?code=pvvmX 提取码:8888
这个AutoJS脚本实现了快手评论采集的基本功能。使用时需要传入视频链接作为参数,脚本会自动滚动加载并保存所有评论。采集的数据包括评论内容、用户ID和位置信息,保存为JSON格式文件。
// 快手评论采集工具 - AutoJS实现版
// 需要开启无障碍服务
auto.waitFor();
device.keepScreenOn();
// 主函数
function main(videoUrl) {
launchKS();
openVideo(videoUrl);
collectComments();
}
// 启动快手APP
function launchKS() {
app.launch("com.kuaishou.nebula");
sleep(5000);
}
// 打开指定视频
function openVideo(url) {
if (url) {
app.openUrl(url);
} else {
toast("请在参数中传入视频链接");
exit();
}
sleep(5000);
}
// 收集评论
function collectComments() {
let comments = [];
let lastComment = null;
let retry = 0;
while (true) {
let currentComments = findComments();
if (currentComments.length === 0) {
retry++;
if (retry > 3) break;
sleep(1000);
continue;
}
let newComments = getNewComments(comments, currentComments);
if (newComments.length === 0) {
scrollComments();
sleep(1500);
continue;
}
comments = comments.concat(newComments);
saveComments(newComments);
lastComment = newComments[newComments.length-1];
scrollComments();
sleep(1500);
}
toast("评论采集完成,共采集到 " + comments.length + " 条评论");
return comments;
}
// 查找评论元素
function findComments() {
return className("android.widget.TextView").find();
}
// 获取新增评论
function getNewComments(allComments, currentComments) {
// 实现去重逻辑
return currentComments.filter(c => !allComments.some(ac => ac.text() === c.text()));
}
// 滚动评论区域
function scrollComments() {
swipe(device.width/2, device.height0.7, device.width/2, device.height0.3, 500);
}
// 保存评论到文件
function saveComments(comments) {
let path = "/sdcard/kscomments" + new Date().getTime() + ".txt";
let content = comments.map(c => {
return {
text: c.text(),
id: c.id(),
bounds: c.bounds()
};
});
files.write(path, JSON.stringify(content));
}
// 使用示例
main("https://v.kuaishou.com/xxxxxx");
// 快手评论采集主程序
const KS_CRAWLER = {
config: {
maxScroll: 100, // 最大滚动次数
saveInterval: 20 // 每20条保存一次
},
init: function() {
this.comments = [];
this.users = new Map();
this.startTime = new Date();
},
start: function(videoUrl) {
this.init();
launchApp('com.kuaishou.nebula');
openVideo(videoUrl);
this.collectData();
this.generateReport();
},
collectData: function() {
for(let i=0; i<this.config.maxScroll; i++) {
let batch = this.scanCurrentPage();
this.processBatch(batch);
if(i % 5 === 0) this.saveToSQLite();
scrollDown();
}
}
// ...其他方法实现...
};
class DataProcessor {
static extractUserInfo(commentNode) {
return {
userId: commentNode.userId,
nickname: commentNode.nickname,
avatar: commentNode.avatar,
vip: commentNode.vipFlag
};
}
static analyzeSentiment(text) {
// 使用简单的情感分析算法
const positiveWords = ['好','棒','喜欢','赞'];
const negativeWords = ['差','垃圾','讨厌'];
let score = 0;
positiveWords.forEach(w => score += text.includes(w) ? 1 : 0);
negativeWords.forEach(w => score -= text.includes(w) ? 1 : 0);
return score > 0 ? 'positive' : score < 0 ? 'negative' : 'neutral';
}
}
function generateCharts() {
const data = STORAGE.queryAnalysisData();
// 使用UI组件生成图表
ui.build([
{
type: 'pie',
title: '评论情感分布',
data: data.sentiment
},
{
type: 'bar',
title: '每小时评论量',
data: data.hourly
}
]);
}