如何统计论坛帖子内每个人的回复信息

查看 19|回复 1
作者:别天王   
就是平常那种论坛,一个帖子每页能容下20条回复,总共有几百页,也就是上千个回复的情况下,怎么统计查看每个人的回复数量以及内容?并且按照升序或者降序排列?网上搜索了半天都没有找到类似的拓展工具,仅有的几个回复都是要通过py爬虫,实在太麻烦了 有什么适合小白的办法吗??
网站现在没有图片直传功能了 网页图片不知道咋上传,就是类似论坛这种回复机制的一般论坛页面,求教了 (没有网页后台)

每个人, 论坛

xiaotian947859   

这个是针对吾爱破解写的一个回复统计和查看  脚本为油猴脚本代码  自己创建一个油猴脚本保存即可 左上角会有分析回复图标  
[Python] 纯文本查看 复制代码// ==UserScript==
// @name         论坛回复分析工具
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  统计论坛帖子中每个用户的回复数量和内容
// @author       Your name
// @match        *://*/*
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
    // 添加样式
    const style = document.createElement('style');
    style.textContent = `
        .reply-analyzer-btn {
            position: fixed;
            top: 20px;
            left: 20px;
            padding: 12px 24px;
            background: linear-gradient(135deg, #4CAF50, #45a049);
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            z-index: 9999;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            font-size: 14px;
            font-weight: 500;
            box-shadow: 0 2px 8px rgba(0,0,0,0.15);
            transition: all 0.3s ease;
        }
        .reply-analyzer-btn:hover {
            background: linear-gradient(135deg, #45a049, #3d8b40);
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(0,0,0,0.2);
        }
        .reply-analyzer-btn:active {
            transform: translateY(1px);
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .reply-analyzer-panel {
            position: fixed;
            top: 20px;
            right: 20px;
            width: 500px;
            max-height: 80vh;
            overflow-y: auto;
            background: white;
            padding: 24px;
            border-radius: 12px;
            box-shadow: 0 4px 24px rgba(0,0,0,0.15);
            z-index: 9999;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255,255,255,0.1);
        }
        .reply-analyzer-panel h3 {
            margin: 0 0 20px 0;
            color: #2c3e50;
            font-size: 20px;
            font-weight: 600;
        }
        .reply-analyzer-panel .user-header {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 12px;
            padding-bottom: 8px;
            border-bottom: 2px solid #f0f2f5;
        }
        .reply-analyzer-panel .username {
            color: #2196F3;
            font-size: 16px;
            font-weight: 600;
            margin: 0;
            text-shadow: 0 1px 1px rgba(0,0,0,0.1);
        }
        .reply-analyzer-panel .reply-count {
            background: linear-gradient(135deg, #e3f2fd, #bbdefb);
            color: #1976D2;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 500;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        }
        .reply-analyzer-panel .reply-content {
            margin: 8px 0;
            padding: 12px;
            background: #f8f9fa;
            border-radius: 8px;
            font-size: 14px;
            line-height: 1.6;
            color: #2c3e50;
            border: 1px solid #e9ecef;
            transition: all 0.2s ease;
        }
        .reply-analyzer-panel .reply-content:hover {
            background: #f1f3f5;
            transform: translateX(2px);
        }
        .reply-analyzer-panel .controls {
            display: flex;
            gap: 12px;
            margin-bottom: 20px;
        }
        .reply-analyzer-panel button {
            padding: 8px 16px;
            border: 1px solid #e0e0e0;
            border-radius: 6px;
            background: white;
            cursor: pointer;
            font-size: 13px;
            font-weight: 500;
            color: #666;
            transition: all 0.2s ease;
        }
        .reply-analyzer-panel button:hover {
            background: #f5f5f5;
            border-color: #d0d0d0;
            color: #333;
        }
        .reply-analyzer-panel .user-section {
            margin-bottom: 24px;
            padding-bottom: 20px;
            border-bottom: 1px solid #eee;
        }
        .reply-analyzer-panel .user-section:last-child {
            border-bottom: none;
            margin-bottom: 0;
            padding-bottom: 0;
        }
        /* 自定义滚动条 */
        .reply-analyzer-panel::-webkit-scrollbar {
            width: 8px;
        }
        .reply-analyzer-panel::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 4px;
        }
        .reply-analyzer-panel::-webkit-scrollbar-thumb {
            background: #c1c1c1;
            border-radius: 4px;
        }
        .reply-analyzer-panel::-webkit-scrollbar-thumb:hover {
            background: #a8a8a8;
        }
    `;
    document.head.appendChild(style);
    // 分析回复
    function analyzeForumReplies() {
        console.log('开始分析...');
        
        // 获取所有回复
        const replies = document.querySelectorAll('.plc');
        console.log('找到回复元素数量:', replies.length);
        
        if (replies.length === 0) {
            alert('未找到任何回复元素,请确保页面已完全加载');
            return;
        }
        
        // 创建用户回复统计对象
        const userStats = {};
        let processedCount = 0;
        
        // 遍历所有回复
        replies.forEach((reply, index) => {
            try {
                // 获取用户名
                const usernameElement = reply.querySelector('.res-author a, .author a, .xi2');
                if (!usernameElement) {
                    console.log(`第 ${index + 1} 个回复未找到用户名元素`);
                    return;
                }
               
                const username = usernameElement.textContent.trim();
               
                // 获取回复内容
                const contentElement = reply.querySelector('.t_f, [class*="message"]');
                if (!contentElement) {
                    console.log(`第 ${index + 1} 个回复未找到内容元素`);
                    return;
                }
               
                const content = contentElement.textContent.trim();
               
                // 初始化用户数据
                if (!userStats[username]) {
                    userStats[username] = {
                        replies: []
                    };
                }
               
                // 更新统计数据
                userStats[username].replies.push(content);
                processedCount++;
               
            } catch (error) {
                console.error(`处理第 ${index + 1} 个回复时出错:`, error);
            }
        });
        
        console.log('成功处理回复数:', processedCount);
        
        if (processedCount === 0) {
            alert('未能成功解析任何回复,请检查页面结构');
            return;
        }
        
        // 转换为数组并排序(按回复数量)
        const sortedStats = Object.entries(userStats)
            .map(([username, data]) => ({
                username,
                count: data.replies.length,
                replies: data.replies
            }))
            .sort((a, b) => b.count - a.count); // 降序排列
        
        // 创建结果面板
        const panel = document.createElement('div');
        panel.className = 'reply-analyzer-panel';
        
        let html = `
            
                用户回复统计
               
                    关闭
               
            
        `;
        
        sortedStats.forEach(stat => {
            html += `
               
                    
                        ${stat.username}
                        ${stat.count} 条回复
                    
                    
                        ${stat.replies.map(reply => `
                            ${reply}
                        `).join('')}
                    
               
            `;
        });
        
        panel.innerHTML = html;
        document.body.appendChild(panel);
    }
    // 添加分析按钮
    function addAnalyzeButton() {
        const button = document.createElement('button');
        button.className = 'reply-analyzer-btn';
        button.textContent = '分析回复';
        button.onclick = analyzeForumReplies;
        document.body.appendChild(button);
    }
    // 等待页面加载完成后添加按钮
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', addAnalyzeButton);
    } else {
        addAnalyzeButton();
    }
})();
您需要登录后才可以回帖 登录 | 立即注册

返回顶部