在线考试翻页抓取题目导出js

bash
// 自动翻页
(async function() {
var ex = window.__kmsExamine;
var total = 50;
var allQuestions = [];
for (var i = 0; i < total; i++) {
// 直接读当前题数据
var topic = ex.__currentExamTopic;
if (topic) {
allQuestions.push({
order: i + 1,
type: topic.typeNameText || topic.typeName,
subject: topic.subject,
options: topic.options || []
});
console.log('✓ 第' + (i+1) + '题: ' + (topic.subject||'').slice(0,20));
}
if (i < total - 1) {
// 模拟点下一题
ex.__jumpOrder = i + 1;
ex.__jumpFdId = ex._fdId_;
await new Promise(function(resolve) {
// 拦截数据加载完成
var origInit = ex.__initTopic__;
// 直接点击下一题按钮
document.querySelector('#lui-id-62, [title="下一题"]').click();
setTimeout(resolve, 1200);
});
}
}
// 生成Word
var html = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"><head><meta charset="utf-8"><style>body{font-family:宋体;font-size:12pt;line-height:2}.q{margin-bottom:16px}.qt{font-weight:bold}.op{margin-left:2em}</style></head><body><h2 style="text-align:center">26年交付体系制度考核-二次开发类</h2>';
allQuestions.forEach(function(q) {
html += '<div class="q"><div class="qt">' + q.order + '.【' + q.type + '】' + q.subject + '</div>';
(q.options || []).forEach(function(opt) {
html += '<div class="op">' + opt.value + '. ' + opt.text + '</div>';
});
html += '</div>';
});
html += '</body></html>';
var blob = new Blob(['\ufeff' + html], {type: 'application/msword'});
var a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = '考试题目.doc';
a.click();
console.log('✅ 完成!共' + allQuestions.length + '题');
window.__examQuestions = allQuestions;
})();