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 Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.
Post Reply
dance4me
Posts: 8
Joined: Mon Sep 25, 2017 2:28 pm

Function into EVAL() ?

Post by dance4me » Tue Sep 26, 2017 10:59 am

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() ?

Post by iimfun » Thu Sep 28, 2017 6:30 am

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() ?

Post by dance4me » Thu Sep 28, 2017 8:54 am

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() ?

Post by iimfun » Tue Oct 17, 2017 6:19 am

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