This commit is contained in:
chekayo
2025-12-07 17:42:28 +08:00
parent 047fa7cb6f
commit 484ab31d8e

View File

@@ -202,22 +202,19 @@ func findCommentElement(page *rod.Page, commentID, userID string) (*rod.Element,
// === 4. 先滚动到最后一个评论(触发懒加载)=== // === 4. 先滚动到最后一个评论(触发懒加载)===
if currentCount > 0 { if currentCount > 0 {
logrus.Infof("滚动到最后一个评论(共 %d 条)", currentCount) logrus.Infof("滚动到最后一个评论(共 %d 条)", currentCount)
_, err := page.Eval(`() => {
const container = document.querySelector('.comments-container');
if (!container) return false;
// 查找最后一个评论 // 使用 Go 获取所有评论元素
const comments = container.querySelectorAll('.parent-comment, .comment-item, .comment'); elements, err := page.Timeout(2 * time.Second).Elements(".parent-comment, .comment-item, .comment")
if (comments.length > 0) { if err == nil && len(elements) > 0 {
const lastComment = comments[comments.length - 1]; // 滚动到最后一个评论
lastComment.scrollIntoView({behavior: 'smooth', block: 'center'}); lastComment := elements[len(elements)-1]
return true; err := lastComment.ScrollIntoView()
}
return false;
}`)
if err != nil { if err != nil {
logrus.Warnf("滚动到最后一个评论失败: %v", err) logrus.Warnf("滚动到最后一个评论失败: %v", err)
} }
} else {
logrus.Warnf("未找到评论元素: %v", err)
}
time.Sleep(300 * time.Millisecond) time.Sleep(300 * time.Millisecond)
} }