起因

学校开展了大学生军事理论答题竞赛,发了个url,要进行答题
请输入图片描述
输入个人信息后,答题,抓包看一下,答案和题目都在响应体中
请输入图片描述
看规律得知,"rightAnswer"值是本题正确答案,让豆包写了个html,复制出来能直接提取所有答案。
请输入图片描述
html的代码如下

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>军事理论题目答案提取工具</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: "Microsoft YaHei", Arial, sans-serif;
        }
        body {
            max-width: 1200px;
            margin: 20px auto;
            padding: 0 20px;
            background-color: #f5f7fa;
        }
        .container {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }
        .card {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 20px;
        }
        h2 {
            color: #34495e;
            font-size: 18px;
            margin-bottom: 15px;
            padding-bottom: 5px;
            border-bottom: 1px solid #eee;
        }
        textarea {
            width: 100%;
            height: 300px;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            resize: vertical;
            font-size: 14px;
            line-height: 1.6;
        }
        textarea:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 2px rgba(52,152,219,0.2);
        }
        .btn {
            padding: 12px 24px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .btn:hover {
            background-color: #2980b9;
        }
        #result {
            min-height: 150px;
            padding: 15px;
            background-color: #f8f9fa;
            border: 1px solid #eee;
            border-radius: 6px;
            font-size: 14px;
            line-height: 1.8;
            white-space: pre-wrap;
            color: #2c3e50;
        }
        .tip {
            font-size: 13px;
            color: #7f8c8d;
            margin-top: 10px;
            line-height: 1.5;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="card">
            <h1>军事理论题目答案提取工具</h1>
            <h2>1. 粘贴TXT文本(含单选/多选题)</h2>
            <textarea id="txtInput" placeholder="请将包含题目信息的TXT文本粘贴到此处...
示例格式:
{...\"rightAnswer\":\"B\",\"answerOrderType\":\"1\",...}
{...\"rightAnswer\":\"ABCD\",\"answerOrderType\":\"1\",...}"></textarea>
            <div class="tip">提示:支持识别TXT中所有包含"rightAnswer"字段的内容,自动提取答案(单选如B、C;多选如ABCD、ABD)</div>
        </div>

        <div class="card">
            <h2>2. 提取答案</h2>
            <button class="btn" onclick="extractAnswers()">点击提取所有rightAnswer值</button>
        </div>

        <div class="card">
            <h2>3. 提取结果(按题目顺序排列)</h2>
            <div id="result">提取结果将显示在这里...
- 若未显示结果,可能是文本格式有误(请确保包含"rightAnswer"字段)
- 多选题答案将完整保留(如ABCD),单选题答案按原文提取(如B)</div>
        </div>
    </div>

    <script>
        function extractAnswers() {
            // 获取输入的文本
            const inputText = document.getElementById('txtInput').value.trim();
            const resultElement = document.getElementById('result');
            
            // 若输入为空,提示用户
            if (!inputText) {
                resultElement.innerHTML = "⚠️ 请先粘贴包含题目信息的TXT文本!";
                resultElement.style.color = "#e74c3c";
                return;
            }

            // 正则表达式:匹配 "rightAnswer":"XXX" 格式,XXX可包含字母、数字、逗号(如ABCD、B、123)
            const regex = /"rightAnswer":"([A-Za-z0-9,]+)"/g;
            const matches = [];
            let match;

            // 循环提取所有匹配的rightAnswer值
            while ((match = regex.exec(inputText)) !== null) {
                matches.push(match[1]); // match[1] 是捕获到的答案内容
            }

            // 处理提取结果
            if (matches.length === 0) {
                resultElement.innerHTML = "❌ 未找到任何rightAnswer字段!\n请检查文本格式,确保包含类似 \"rightAnswer\":\"B\" 或 \"rightAnswer\":\"ABCD\" 的内容。";
                resultElement.style.color = "#e74c3c";
            } else {
                let resultText = `✅ 共提取到 ${matches.length} 个答案,按顺序排列如下:\n`;
                matches.forEach((answer, index) => {
                    resultText += `\n${index + 1}. ${answer}`;
                });
                resultElement.innerHTML = resultText;
                resultElement.style.color = "#2c3e50";
            }
        }

        // 可选:按下Ctrl+Enter快速提取
        document.getElementById('txtInput').addEventListener('keydown', function(e) {
            if (e.ctrlKey && e.key === 'Enter') {
                e.preventDefault();
                extractAnswers();
            }
        });
    </script>
</body>
</html>

嗯,随手一记

  • 本文作者:柒葱
  • 本文链接:https://tkkkk.tk/64
  • 版权声明:本站发布的文章及教程仅限用于学习和研究目的.请勿用于商业或违法用途,否则后果请用户自负,本站不承担任何责任! 如涉及版权问题请及时与站长联系:m@tkkkk.tk,我们会在第一时间删除资源。