1

我找到了这个示例代码,我可以在其中自动替换页面中的某些内容

// If content-type is HTML, then remove all DIV tags
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
  // Remove any compression or chunking
  oSession.utilDecodeResponse();

  var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);

  // Replace all instances of the DIV tag with an empty string
  var oRegEx = /<div[^>]*>(.*?)<\/div>/gi;
  oBody = oBody.replace(oRegEx, "");

  // Set the response body to the div-less string
  oSession.utilSetResponseBody(oBody);
}

但是我怎样才能要求新值,而不是自动替换它?

4

1 回答 1

0

看看这是否适合你

if (oSession.uriContains("/yoururl/here")) {
    oSession.utilDecodeResponse();
    var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
    var oRegEx = /this text will be replaced everywhere/gi;
    var mydefaulttext = 'new text';
    var mymsgbox = FiddlerScript.prompt('Lets change something', mydefaulttext);
    oBody = oBody.replace(oRegEx, mymsgbox);
    oSession.utilSetResponseBody(oBody);
}

OnBeforeResponse

于 2012-04-19T12:11:53.557 回答