EVAL returning duplicated value OR wront SET command error

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
Post Reply
fabiopittol
Posts: 1
Joined: Tue May 16, 2017 4:28 pm

EVAL returning duplicated value OR wront SET command error

Post by fabiopittol » Tue May 16, 2017 4:49 pm

Hi guys,

I'm trying to save a bunch of photos but instead of using the URL file name, my goal is to rename it with the photo ID found in the URL also. The plan is:

1. The macro runs on a page like this:
https://www.motorsport.com/all/photo/ma ... /?a=906516
2. Then it finds the main image URL, which is:
https://cdn-1.motorsport.com/images/mgl ... -honda.jpg
3. Replace the "s8" text to "s7", in order to change the image resolution. And opens the new URL.
4. Use regex to get the image ID from the URL. Which is the "2epn5ab0" between "mgl" and "s7".

-------------------------

I'm managing to get to step 3 without problems with this code:

Code: Select all

TAG POS=1 TYPE=IMG ATTR=SRC:*images/mgl* EXTRACT=HREF
SET newURL EVAL("\"{{!EXTRACT}}\".replace(\"s8\", \"s7\");")
URL GOTO={{newURL}}
But here is where things start to go wrong.

I tried to follow the same EVAL syntax as above to match the image ID like this:

Code: Select all

SET partialID EVAL("\"{{newURL}}\".match(\"(?=mgl\/)(.*)(?=\/s7)\");")
PROMPT {{partialID}}
But that returns a duplicated value. Like this "mgl/2epn5ab0,mgl/2epn5ab0"

-------------------------

Then I found a few possible solutions on Stackoverflow and tried like this suggestion.

Code: Select all

SET partialID EVAL("var s=\"{{newURL}}\"; s.match(\"(?=mgl\/)(.*)(?=\/s7)\"); s[0];")
But all I get using this kind of syntax is the following error:
MacroSyntaxError: wrong format of SET command, line 9 (Error code: -910)




Any ideas of what I might be missing?

P.S.: iMacros for Firefox 9.0.3
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: EVAL returning duplicated value OR wront SET command err

Post by chivracq » Wed May 17, 2017 9:12 pm

fabiopittol wrote:Hi guys,

I'm trying to save a bunch of photos but instead of using the URL file name, my goal is to rename it with the photo ID found in the URL also. The plan is:

1. The macro runs on a page like this:
https://www.motorsport.com/all/photo/ma ... /?a=906516
2. Then it finds the main image URL, which is:
https://cdn-1.motorsport.com/images/mgl ... -honda.jpg
3. Replace the "s8" text to "s7", in order to change the image resolution. And opens the new URL.
4. Use regex to get the image ID from the URL. Which is the "2epn5ab0" between "mgl" and "s7".

-------------------------

I'm managing to get to step 3 without problems with this code:

Code: Select all

TAG POS=1 TYPE=IMG ATTR=SRC:*images/mgl* EXTRACT=HREF
SET newURL EVAL("\"{{!EXTRACT}}\".replace(\"s8\", \"s7\");")
URL GOTO={{newURL}}
But here is where things start to go wrong.

I tried to follow the same EVAL syntax as above to match the image ID like this:

Code: Select all

SET partialID EVAL("\"{{newURL}}\".match(\"(?=mgl\/)(.*)(?=\/s7)\");")
PROMPT {{partialID}}
But that returns a duplicated value. Like this "mgl/2epn5ab0,mgl/2epn5ab0"

-------------------------

Then I found a few possible solutions on Stackoverflow and tried like this suggestion.

Code: Select all

SET partialID EVAL("var s=\"{{newURL}}\"; s.match(\"(?=mgl\/)(.*)(?=\/s7)\"); s[0];")
But all I get using this kind of syntax is the following error:
MacroSyntaxError: wrong format of SET command, line 9 (Error code: -910)

Any ideas of what I might be missing?

P.S.: iMacros for Firefox 9.0.3

Code: Select all

P.S.: iMacros for Firefox 9.0.3
=> FCIM...! :mrgreen: (Read my Sig...)
Well, this is no "PS" Info, this belongs to the Top of your Post and is the first Info I check in a Thread to decide if I will read and certainly answer/do some Digging...
=> Mention your FCI for me to do some "Digging"..., but hum, if you are already (thinking of) using 'REGEX', I guess you should be able to find a Solution by yourself and you very correctly use 'PROMPT' to follow your Vars and debug your Script... :wink:

"My" Solution I think, if I need to dig into your Case/Code/Site, will probably be using 'split()' instead of 'REGEX' that I don't like... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply