EVAL returning duplicated value OR wront SET command error

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.

Moderators: Community Moderators, iMacros Moderators

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.

EVAL returning duplicated value OR wront SET command error

by fabiopittol on Tue May 16, 2017 9:49 am

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
fabiopittol
 
Posts: 1
Joined: Tue May 16, 2017 9:28 am

Re: EVAL returning duplicated value OR wront SET command err

by chivracq on Wed May 17, 2017 2: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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5730
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to iMacros for Firefox

Who is online

Users browsing this forum: Bing [Bot] and 6 guests

Website Monitoring