please help me with a fiddlerscript

1 Answer 481 Views
Fiddler Classic FiddlerCore Windows
eric
Top achievements
Rank 1
eric asked on 13 Jul 2021, 01:38 PM | edited on 14 Jul 2021, 03:25 PM

i need to replace 2 dynamic values from a website ! everytime when i visit website i will see randomize numbers like a clock ! and i need to catch the values to replace with anothers. i attached a PART of the website to see it !

i have tryed this and not work :

 

  static function OnBeforeResponse(oSession: Session) {
        if (m_Hide304s && oSession.responseCode == 304) {
            oSession["ui-hide"] = "true";
        }
        if(oSession.HostnameIs("example.com"))
        {
            oSession.bBufferResponse = true;
            oSession.utilDecodeResponse();
        
            var pattern = '<SPAN
        id=ValueA class=CSItemLabel
        style="FONT-SIZE: 11px; HEIGHT: 17px; WIDTH: 120px; FONT-WEIGHT: bold; COLOR: green; PADDING-BOTTOM: 2px; TEXT-ALIGN: left; PADDING-TOP: 0px; PADDING-LEFT: 2px; DISPLAY: inline-block; PADDING-RIGHT: 0px; BACKGROUND-COLOR: #efefef\">(?<VAL>.*)</SPAN>';        
                    
            var sNewBody: Match = Regex.Match(oSession.GetResponseBodyAsString(),pattern);
            var valueA = sNewBody.Groups["VAL"].Value;

        
            pattern = '<SPAN id=ValueB
        class=CSItemLabel
        style="FONT-SIZE: 11px; HEIGHT: 17px; WIDTH: 145px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; TEXT-ALIGN: left; PADDING-TOP: 0px; PADDING-LEFT: 2px; DISPLAY: inline-block; PADDING-RIGHT: 0px; BACKGROUND-COLOR: #efefef\">(?<VAL>.*)</SPAN>';
            var sNewBody2 : Match = Regex.Match(oSession.GetResponseBodyAsString(),pattern);
            var valueB = sNewBody2.Groups["VAL"].Value;
        
            var strContent = oSession.GetResponseBodyAsString().Replace(valueA,"99.614,99").Replace(valueB,"88.123,88");
        
            oSession.utilSetResponseBody(strContent);
        }
    }

 

also i tryed this :

if (oSession.HostnameIs("https://example.com) && oSession.url.EndsWith("etc.aspx"))
{   
   oSession.utilDecodeResponse();
   var sBody = oSession.GetResponseBodyAsString();
   sBody = Regex.Replace(sBody, "(<SPAN id=ValueA class=CSItemLabel[^>]+>)[^<]+", "$1 99.614,99");
   sBody = Regex.Replace(sBody, "(<SPAN id=ValueB class=CSItemLabel[^>]+>)[^<]+", "$1 88.123,88");
   oSession.utilSetResponseBody(sBody);
}
 

no success ! please help me somebody !

i attached the files to see it ! thanks in advice !

Oskars
Top achievements
Rank 1
Iron
commented on 13 Jul 2021, 06:58 PM

Hello!
I think the values might be generated by JavaScript. Are you able to check the Javascript source to find where these values might originate from? (you can do a id search in any browsers developers tools and see what you find - maybe a function that generates them or even a callback to website (but then you should see the answers as seperate request at fiddler as well..)
Oskars
Top achievements
Rank 1
Iron
commented on 13 Jul 2021, 07:35 PM | edited

I am just wondering whether you have chosen the proper tool for what are you trying to achieve.. There is selenium,
symfony/panther and other tools and headless browsers and even possibility to drive a graphical browser (with selenium, for example chromedriver or geckodriver...) - who can execute javascript and let you interact with the document with changed values...
Of course it is possible theoretically to write a duplicate of javascript logic in the fiddler script. But is that needed?
Zhivko
Telerik team
commented on 15 Jul 2021, 12:24 PM

Hi Eric,

When it comes to modifying responses, it's very important to make sure Fiddler is working in buffered mode. To make sure this is done for the particular session, please handle the OnBeforeRequest event and set the oSession.bBufferResponse property to true. You can find more info about buffered/streaming mode here. Also, you can take a look at this article, which explains which is the appropriate event to set the mentioned property for the session (note: the article is for FiddlerCore, but it can be directly applied for FiddlerScript as well).

As for modifying the response, oSession.utilSetResponseBody(sBody) is indeed the correct way to modify the response, however i see 2 issues with the sample code above:

In the oSession.Hostnameis method, you shouldn’t pass protocol, only the domain (e.g example.com).
Also, from the sample html you’ve provided, I’ve noticed there are a lot of whitespaces, which could be why it’s not working for you. You can try removing them before trying to replace the rest of the body. For example, you could do something like this:

sBody = Regex.Replace(sBody, @"(\s){​​​​​​​​2,}​​​​​​​​", " “); 
If that doesn't work, please try replacing the entire body to something else entirely. This will tell us if the problem is with modifying the response or with the RegEx.

Regards,

Zhivko

1 Answer, 1 is accepted

Sort by
0
Oskars
Top achievements
Rank 1
Iron
answered on 13 Jul 2021, 08:28 PM

Hello!
Turns out that a bit lower there is the answer button!!!

So I advice you to pick the right tooling for your task, something like selenium for c# where you can get the values as you see them in a normal browser...

Hope this helps,

Oskars

Tags
Fiddler Classic FiddlerCore Windows
Asked by
eric
Top achievements
Rank 1
Answers by
Oskars
Top achievements
Rank 1
Iron
Share this question
or