Page 1 of 1

Function into EVAL() ?

Posted: Tue Sep 26, 2017 3:59 am
by dance4me
Hello to everyone, I'm currently having a problem with my code.

I'm currently using iMacros build 844 on Google Chrome and on Windows 10 in french.

Let me explain you. My goal is to take a part of the URL and to change juste a number into it, adding it 1.

Here is my code :


VERSION BUILD=844 RECORDER=CR
SET !TIMEOUT_PAGE 15
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO

SET !VAR1 {{!URLCURRENT}}

SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\";
function incremente(expression){
var expression1 = "";
expression1 = expression.match(/\d{1,}/);
expression1 = expression1 + 1;
expression1 = '&page' + expression1 + '&';
return expression1;}
s.replace(/&page=\d{1,}&/, incremente(/&page=\d{1,}&/));")

PROMPT {{!VAR1}}
PROMPT {{!VAR2}}



And this does not work telling me : SyntaxError: wrong format of SET command...

Is it possible to declare a function directly into an EVAL() in iMacros? I've been looking for some answers on the web and it's a bit difficult to find.

If someone could help me, it would be nice! Best regards.

Re: Function into EVAL() ?

Posted: Wed Sep 27, 2017 11:30 pm
by iimfun
Hello,
dance4me wrote:Is it possible to declare a function directly into an EVAL() in iMacros?
Why not?

Code: Select all
SET !EXTRACT someStuff&page=100&someStuffAgain

SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\"; function incremente(expression){var expression1 = parseInt((\"\" + expression).match(/\\d{1,}/)) + 1; expression1 = '&page=' + expression1 + '&'; return expression1;} s.replace(/&page=\\d{1,}&/, incremente(s.match(/&page=\\d{1,}&/)));")

PROMPT {{!EXTRACT}}
PROMPT {{!VAR2}}

Re: Function into EVAL() ?

Posted: Thu Sep 28, 2017 1:54 am
by dance4me
Thank you very much for sharing your knowledge!


Question :

May I ask why you use : parseInt((\"\" + expression).match(/\\d{1,}/))
instead of parseInt(expression.match(/\\d{1,}/)) ?

Remark :

You wrote : s.replace(/&page=\\d{1,}&/, incremente(s.match(/&page=\\d{1,}&/)));")
I would think there is no need to \\ in the match parenthesis since s.match is waiting for a regex. Don't you think so?


Thanks again and have a good day :-)

Re: Function into EVAL() ?

Posted: Mon Oct 16, 2017 11:19 pm
by iimfun
dance4me wrote:Don't you think so?
Just feel free to edit the macro as you'd like.