## Function into EVAL() ?

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
dance4me
Posts: 8
Joined: Mon Sep 25, 2017 2:28 pm

### Function into EVAL() ?

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.
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

### Re: Function into EVAL() ?

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}}``````
dance4me
Posts: 8
Joined: Mon Sep 25, 2017 2:28 pm

### Re: Function into EVAL() ?

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
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

### Re: Function into EVAL() ?

dance4me wrote:Don't you think so?
Just feel free to edit the macro as you'd like.