// "id" : "1009", // "type" : "choice", // "stem" : "计算机感染特洛伊木马后的典型现象是( )。", // "options" : { // "A" : "程序异常退出", // "B" : "有未知程序试图建立网络连接", // "C" : "邮箱被垃圾邮件填满", // "D" : "Windows 系统黑屏" // }, // "answer" : "B", // "key_points" : "空", // "analysis" : "计算机感染特洛伊木马后,会受到特洛伊木马程序的控制,有以下几种典型现象。●有未知程序试图建立网络连接。●系统中有可疑的进程在运行等现象。●系统运行速度越来越慢,且CPU资源占用率高。●任务表中有可疑的文件在运行。●系统长时间读/写硬盘或搜索软盘。●系统经常死机或重启等。", // "tags" : null, // "knowledgeId" : [ "CF.NCB", "CF.SSDM" ], // "lastModified" : "2020-03-11 19:29:37", var request = require("request"); var fs = require('fs'); let startNum=0; var options = { url:'https://zhjts.learncoder.com:5555/question/api/v1/category/get/exercise?categoryId='+startNum }; function get(opts) { return new Promise ((resolve, reject) => { request.get(opts,function(err,response,body){ if(!err && response.statusCode == 200){ if(body!=='null'){ results=JSON.parse(body); resolve(results); } } }); }); } canhoice=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] questionType = { "1":"choice", "0":"true_false", "2":"multiple_choice", "3":"blank", "4":"short_answer" } var categoryList=[]; categoryList.push({ id:0, name: "练习", parentId: 0, hasChild: true, orderNum: 0, hasNew: false }); var totalList=[]; let pormis= crawler(categoryList); pormis.then(result=>{ console.log(totalList.length); let obj = { "totalList": totalList, "length": totalList.length }; fs.writeFileSync('output.json', JSON.stringify(obj)); }) //使用它 async function crawler(categoryList) { // console.log(categoryList[categoryList.length-1].name) let result = await get(buildCateOptions(categoryList[categoryList.length-1].id)); for(let i of result.res){ categoryList.push(i); if(i.hasChild){ await crawler(categoryList); }else{ let key_points="知识点"; for(let cate of categoryList){ key_points=key_points+"."+cate.name; } // totalList.push(key_points); let retlist = await getQuestion(i.id,key_points); for(let j of retlist){ totalList.push(j); } } categoryList.pop(); } return result; } function buildQuestionOptions(id){ let option = { url:'https://zhjts.learncoder.com:5555/question/api/v1/exercise/questions/get/auth?page=0&size=1000&categoryId='+id }; return option; } // getQuestion(94,"112231"); async function getQuestion(id,key_points){ let retList=[] let res = await get(buildQuestionOptions(id)); for(let q of res.res.data){ let newQ={ }; newQ.id="learncoder_"+id+"_"+q.id; newQ.stem=q.stem; newQ.key_points=key_points; if(q.analysis===null||q.analysis=="[analysis]空"){ newQ.analysis='空'; }else{ newQ.analysis=q.analysis.replace("[analysis]","").replace("【考点】","");; } newQ.type=questionType[''+q.questionType]; let ind; switch(q.questionType){ case 0://判断题 newQ.answer=q.answer; break; case 1://选择题 newQ.options={} newQ.answer=""; ind=0; for(let opt of q.options){ let choice =canhoice[ind]; ind++; let content= opt.content; if(opt.content.charAt(1)=='.'){ choice = opt.content.slice(0,1) content= opt.content.slice(2) } newQ.options[choice]=content; if(opt.correct){ newQ.answer=choice; } } break; case 2://多选题 newQ.options={} newQ.answer=""; ind=0; for(let opt of q.options){ let choice =canhoice[ind]; ind++; let content= opt.content; if(opt.content.charAt(1)=='.'){ choice = opt.content.slice(0,1) content= opt.content.slice(2) } newQ.options[choice]=content; if(opt.correct){ newQ.answer=newQ.answer+";"+choice; } } newQ.answer=newQ.answer.slice(1); break; case 3://填空题 newQ.options={} q.answer=""; for(let opt of q.blanks){ let choice = opt.blankId let content= opt.blankAnswer[0] newQ.options[choice]=content; } q.answer=q.answer.slice(1); break; case 4://简答题 newQ.answer=q.answer.replace("[answer_question_answer]","") break; default: console.log(q); throw new Error('questionType error='+q.questionType); } retList.push(newQ); } // console.log(retList); return retList; } function buildCateOptions(id){ let option = { url:'https://zhjts.learncoder.com:5555/question/api/v1/category/get/exercise?categoryId='+id }; return option; }