【fiddler script】我司答* 脚本
本帖最后由 orpheus 于 2020-6-12 12:26 编辑适用于限时答题类型,对战不行。
在cachingPaper.do的response中,已经返回了答案:
选择题的每个选项都用 "isCorrect": false,、"isCorrect": true 进行了标注
判断题用 "correctAnswer": "1", 或"correctAnswer": "2",
如此,问题就简单了,就是json处理,然后修改ResponseBody,为防意外情况,我加了个写txt
就是简单的js脚本,还请大家斧正:
if (oSession.fullUrl.Contains("cachingPaper.do")){
var jsonString = oSession.GetResponseBodyAsString().replace(/[\r\n ]/g, "");
var qarr= jsonString.split("isCorrect\":true");
var qlength = qarr.length;
writeFile(filetemp, jsonString);
for (var x:int = 0; x < qlength-1; x++){
var qarr1= qarr.split("content\":\"");
var answer = qarr1;
var end = answer.indexOf("\",\"showOrder",);
writeFile(filetemp,answer.substring(0,end));
//输出
oSession.utilReplaceInResponse(answer,"★"+answer)
}
var jsonString_new = oSession.GetResponseBodyAsString().replace(/[\r\n ]/g, "");
var qarrb= jsonString_new.split(",\"corpCode\"");
var qlengthb = qarrb.length;
for (var y:int = 0; y < qlengthb-1; y++){
var strjudgment = qarrb.substring(qarrb.indexOf("correctAnswer\":\""))
var isjudgment = qarrb.indexOf("correctAnswer\":\"");
if (isjudgment > 0){
var answertemp ="-"
var titlejudgment = qarrb.match(/(?<=questionAnalyze\"\:\").*?(?=.\",\"language)/);
var answerjudgment = qarrb.match(/(?<=correctAnswer\"\:\").*?(?=.,\"employeeCode)/);
if (answerjudgment == "1") {
answertemp = "对"
}
if (answerjudgment == "2") {
answertemp = "错"
}
//输出
oSession.utilReplaceInResponse(titlejudgment,answertemp+"★"+titlejudgment)
writeFile(filetemp,answertemp+" | "+titlejudgment);
}
}
writeFile(filetemp,oSession.GetResponseBodyAsString().replace(/[\r\n ]/g, ""));
}
遇到的问题:
1.打算用正则来截取多个题目串到arr,在测试工具中可以截取到多个,但是实际跑起来,只会取到第一个,原因未知,求指教
2.js取json成员,有好的办法吗,我尝试了一圈,没找到,万望赐教
3.用易语言编写的话,取json就简单了,但是没找到易语言调用fiddler实现数据重放、加载存档的功能。因为只能答1次题,需要数据重放进行测试。 iso 发表于 2020-6-22 09:32
writeFile这个函数和两个参数(filetemp1、filetemp)是如何定义的
static function writeFile(filename,context)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(filename,8 );
f.writeLine(context);
f.Close();
}
var filetemp ="D:\\fiddler\\temp.txt";
var filetemp1 ="D:\\fiddler\\responbody.txt";
这两个随意 var jsonStr = Fiddler.WebFormats.JSON.JsonDecode(oSession.GetResponseBodyAsString());
FiddlerApplication.Log.LogString(jsonStr.JSONObject['rows']["id"]);
自带解析json的方法 直接调用即可 代码跑不起来,有完整的吗?
李玉风我爱你 发表于 2020-6-12 23:26
var jsonStr = Fiddler.WebFormats.JSON.JsonDecode(oSession.GetResponseBodyAsString());
FiddlerAppl ...
感谢老兄指教{:1_893:} iso 发表于 2020-6-16 11:23
代码跑不起来,有完整的吗?
if (oSession.fullUrl.Contains("cachingPaper.do")){
var jsonString = oSession.GetResponseBodyAsString().replace(/[\r\n ]/g, "");
var qarr= jsonString.split("isCorrect\":true");
var qlength = qarr.length;
writeFile(filetemp1, jsonString);
for (var x:int = 0; x < qlength-1; x++){
var qarr1= qarr.split("content\":\"");
var answer = qarr1;
var end = answer.indexOf("\",\"showOrder",);
writeFile(filetemp,answer.substring(0,end));
//输出
oSession.utilReplaceInResponse(answer,"★"+answer)
}
var jsonString_new = oSession.GetResponseBodyAsString().replace(/[\r\n ]/g, "");
var qarrb= jsonString_new.split(",\"corpCode\"");
var qlengthb = qarrb.length;
for (var y:int = 0; y < qlengthb-1; y++){
var strjudgment = qarrb.substring(qarrb.indexOf("correctAnswer\":\""))
var isjudgment = qarrb.indexOf("correctAnswer\":\"");
if (isjudgment > 0){
var answertemp ="-"
//writeFile(filetemp,qarrb);
//var titlejudgment = qarrb.match(/(?<=questionAnalyze\"\:\").*?(?=.\",\"language)/);
var titlejudgment = qarrb.match(/(?<=itemName\"\:\").*?(?=.\",\"examBaseId)/);
var answerjudgment = qarrb.match(/(?<=correctAnswer\"\:\").*?(?=.,\"employeeCode)/);
if (answerjudgment == "1") {
answertemp = "对"
}
if (answerjudgment == "2") {
answertemp = "错"
}
//输出
oSession.utilReplaceInResponse(titlejudgment,answertemp+"★"+titlejudgment)
writeFile(filetemp,answertemp+" | "+titlejudgment);
}
}
writeFile(filetemp1,oSession.GetResponseBodyAsString().replace(/[\r\n ]/g, ""));
}
放OnBeforeResponse下 orpheus 发表于 2020-6-22 08:47
if (oSession.fullUrl.Contains("cachingPaper.do")){
var...
writeFile这个函数和两个参数(filetemp1、filetemp)是如何定义的
页:
[1]