peppe1 wrote:hi,
the closest match I could find is here:
http://forum.imacros.net/viewtopic.php? ... EAS#p57515
basically, it is about setting the extraction to a variable using an EVAL() with a conditional statement if {} nested inside of it.
Code: Select all
VERSION BUILD=8601111 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP YES
URL GOTO=http://shop2.gzanders.com/mb-930-jm-pro-series-10-shot-24-vr-matte-black-synthetic.html
TAG POS=7 TYPE=SPAN FORM=ACTION:http://shop2.gzanders.com/checkout/cart/add/uenc/aHR0cDovL3Nob3AyLmd6YW5kZXJzLm* ATTR=* EXTRACT=TXT
SET !VAR1 EVAL("if (\"{{!EXTRACT}}\" == \"Out of stock\") {var s = \"\";} else {var s = \"C:\\\Windows\\\Media\\\chimes.wav\";} s;")
'PROMPT !EXTRACT:<SP>{{!EXTRACT}}<br>!VAR1:<SP>{{!VAR1}}
URL GOTO=file://{{!VAR1}}
URL GOTO=http://shop2.gzanders.com/mb-930-jm-pro-series-9-shot-22-vr-matte-black-synth.html
TAG POS=7 TYPE=SPAN FORM=ACTION:http://shop2.gzanders.com/checkout/cart/add/uenc/aHR0cDovL3Nob3AyLmd6YW5kZXJzLm* ATTR=* EXTRACT=TXT
SET !VAR1 EVAL("if (\"{{!EXTRACT}}\" == \"Out of stock\") {var s = \"\";} else {var s = \"C:\\\Windows\\\Media\\\chimes.wav\";} s;")
'PROMPT !EXTRACT:<SP>{{!EXTRACT}}<br>!VAR1:<SP>{{!VAR1}}
URL GOTO=file://{{!VAR1}}
My problems arise from multiple angles. To pinpoint:
1. I am extracting multiple elements from one page during a single run of the loop from the DATASOURCE.
2. (Good thing) only one element (H1) is relevant to verify the condition upon SAVEAS
3. In case that condition is evaluated to positive ( I mean text is "0 products exist" ) I need to stop extraction from that page and jump to the next string in the DATASOURCE csv and perform a new search
Dear Master wizard, help me.
Later edit:
I found a closer example in the Eval.iim
Code: Select all
SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\", d = parseFloat(s); if(d > 99 && d < 101) d; else MacroError(\"Value is not in the set range\")")
how can I switch MacroError to some GOTO script line number or something.
Thank you very much.
OK..., the Thread you found was/is for a Conditional Sound, but the Principle is more or less the same like what you'll need, at least to make your Script in pure '.iim' without using a '.js' Script which is anyway always the "Standard" way if you want to include some Conditional Behaviour in your Script.
I managed to locate
another Thread which is a bit closer, from 2 years ago as well, but I didn't give much Details:
chivracq wrote:sleepysentry wrote:...
5. If <div class="messageText">No matches found</div> appears on the page, add TICKET_NUMBER to a list of failed searches
...
...
5- Use 'SAVEAS' and 'EVAL' for a Conditional Save to a local .TXT File based on 'TAG' + 'EXTRACT' or use a .js Script for the Conditional part.
...
In a Nutshell, the Principle for a Conditional Sound is using 'EVAL()' to compute a String that will be the Path to a Sound File (or an empty String for no Sound) that will be reused and played with 'URL GOTO'.
For a Conditional 'SAVEAS', the Principle is the same, the String that you will compute with 'EVAL()' will be the File Name (with Extension, "Products.csv" for example) or an Empty String or a different Temp File Name for the 'Product not found' Pages, that you'll be able to delete from time to time, and that Computed String will be used for the 'FILE' Parameter for the 'SAVEAS'.
3. In case that condition is evaluated to positive ( I mean text is "0 products exist" ) I need to stop extraction from that page and jump to the next string in the DATASOURCE csv and perform a new search
Hum, there are 3 ways to get to the Result that you want...:
1- Like you mention, to "stop" the Extraction, using 'EVAL()' + 'MacroError()' like you found, and/but you'll need a main '.js' Script to handle the Looping.
2- Keep doing the "Fake" Extraction even if there is nothing to extract, and the Conditional SAVEAS with my Method will save or not the EXTRACT, or save it to 2 different Files. If you are going to get several/many "#EANF#", you'll need to use a short '!TIMEOUT_STEP' (0 or 1) to speed up the fake Extractions, together with '!ERRORIGNORE'.
3- If once you've identified the first '#EANF#' or "0 products exist", it is possible using 'EVAL()' to compute a '1 / 0' to use for 'TAG POS=n' for all Extracts you do after that, 'TAG POS=0' won't do/extract anything...
I would go (and I already use it in one of my Macros...!) for Method 2, but/because I never use 'js' Scripts...
I actually don't remember if I use an Empty String or a String for a Temp File to delete from time to time for the Records I don't want to keep, I haven't checked that folder for months, I might have some huge Temp File to delete..., ah-ah...!, oops...!
- (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...