How to replace "()" from extracted text with some other character in Imacros - imacros

I want to extract image name and then use the name to save the image
here is the js code that i use
macro += "TAG POS=1 TYPE=SPAN ATTR=ID:txt2ArtikelNr EXTRACT=TXT" + "\n";
...
...
..
macro += "ONDOWNLOAD FOLDER=* FILE={{!EXTRACT}}.jpg WAIT=YES" + "\n";
It works fine until there are brackets () in the image name. In this case it does not download the image.
e.g. If image name A123, it works fine.
If image name A (123), it does not download image
and gives me this error wrong format of SET command, line 4 (Error code: 910)
Thanks in advance
I am using firefox 38.0.5, and imacros addon 8.9.2.1

SET !EXTRACT EVAL("'{{!EXTRACT}}'.replace(/[\\(\\)]/g, '');")
If you want to replace the space sign as well, just add it into the square brackets.
And here is the code for your js-script:
macro += 'SET !EXTRACT EVAL("\'{{!EXTRACT}}\'.replace(/[\(\)]/g, \'\');")' + "\n";

Related

IMacros Extract, How to extract title from html code using IMacros and RegEx?

I want to extract the title from an HTML code, using Imacros and RegEx, the title is wrapped in some code that I want to filter out, I don't know how to use EVAL neither RegEx, I just found some RegEx that worked with my code, so it extracts the title from other codes,
but I am not sure how to use it with Imacros, appreciate it if anyone knows how to make it work, whether with RegEx or other ways.
Here is the html part:
<a data-test-id="search-guide" href="" title="Search for "skin care routine""><div
class="Jea Lfz XiG fZz gjz qDf zI7 iyn Hsu" style="white-space: nowrap; background-color: rgb(115,
115, 115);"><div class="tBJ dyH iFc MF7 erh tg7 IZT mWe">Routine</div></div></a>
the part from the title I want is: skin care routine
the RexEx part that I use:
title="Search for "([^"]*)"
and here is my Imacros:
TAG POS=3 TYPE=a ATTR=data-test-id:search-guide EXTRACT=href
SET !VAR1 EVAL('s = '{{!EXTRACT}}'[title='Search for "([^']*)"]')
PROMPT {{!EXTRACT}}
I get an error on the EVAL Line:
wrong format of SET command, line 15 (Error code: -910)
OK, I got it working, Here is the working code:
TAG POS=3 TYPE=A ATTR=data-test-id:search-guide EXTRACT=TITLE
SET !VAR1 EVAL("\"{{!EXTRACT}}\".substr(10,100);")
PROMPT {{!VAR1}}
Several "Mistakes" in your Script and Approach indeed...
'EXTRACT=HREF' won't get you anywhere, => simply use directly 'EXTRACT=TITLE' + 'EVAL()' (with 'replace()' if you don't mind keeping the Double Quotes, or 'split()' if you want to get rid of them)...
(Much easier without 'RegEx' anyway...)
(Spell "iMacros" correctly (x5) + Add a Question Mark to your Title (you are not sharing a 'HowTo'...) + Mention your FCI if you need me to "elaborate" in more Details...)

go to the next step if {{!EXTRACT}} is true

i'm new here and newbie in imacros and javascript
I have made a script that will extract a random word from a page with a regex syntax.
The script is working fine, is going to page.. is search for the word and if is there will extract the word.
But i need that the script is to refresh the page until the word is found and after that to run the second imacro script
VERSION BUILD=8961227 RECORDER=FX
SET !TIMEOUT 1
SET !ERRORIGNORE YES
TAB T=1
URL GOTO=url
SEARCH SOURCE=REGEXP:"raspuns":\[\"(.[^"]*)" EXTRACT=$1
SET !VAR1 {{!EXTRACT}}
and if the word is found run the second script (if not refesh)
TAB T=2
URL GOTO=url
TAG POS=1 TYPE=TEXTAREA ATTR=AUTOCOMPLETE:off CONTENT={{!EXTRACT}}
TAG POS=1 TYPE=BUTTON ATTR=CLICK:sendMessage()&&CLASS:go&&TXT:
anyone can help me with this?
Not super sure if I know exactly what you want and as it is imacros there are some weird workarounds but this might help you
VERSION BUILD=8961227 RECORDER=FX
SET !TIMEOUT 1
SET !ERRORIGNORE YES
TAB T=1
URL GOTO=url
SEARCH SOURCE=REGEXP:"raspuns":\[\"(.[^"]*)" EXTRACT=$1
SET !VAR0 raspuns
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT NULL
SET !VAR2 EVAL("('{{!VAR0}}' == '{{!VAR1}}') ? 1 : 0;")
TAB T=2
URL GOTO=url
TAG POS={{!VAR2}} TYPE=TEXTAREA ATTR=AUTOCOMPLETE:off CONTENT={{!EXTRACT}}
TAG POS={{!VAR2}} TYPE=BUTTON ATTR=CLICK:sendMessage()&&CLASS:go&&TXT:
As you didnt give a url its very hard for me to test, but point is, if if takes the word youre looking for, raspun, it will set the TAG position to 1, therefore tagging what you need, but if it doesnt, it will set the TAG pos = 0, therefore just passing through the code, hope that helps

Wrong format of SET

I want to run my script to check if the fuel value is above 150 to do if/else stuff.
When I try to run the script it returns with
wrong format of SET command, line 8 (Error code: 910)"
VERSION BUILD=8940826 RECORDER=FX
TAB T=1
URL GOTO=https://cannonsatoshi.com/account
TAG POS=1 TYPE=P ATTR=ID:fuel_value* EXTRACT=TXT
SET !EXTRACT_TEST_POPUP NO
SET !VAR2 {{!EXTRACT}}
SET !VAR3 EVAL(" if {{!VAR2}}=>150{
iimPlay("loop2.iim")
} else {
iimPlay("Wait.iim")
} ")
Don’t confuse Scripting Interface with the EVAL command (where only “pure” JavaScript is possible). If you want to use ‘if’-clause, try js-script like this:
iimPlayCode("TAB T=1" + "\n" + "URL GOTO=https://cannonsatoshi.com/account" + "\n" + "TAG POS=1 TYPE=P ATTR=ID:fuel_value* EXTRACT=TXT" + "\n");
if (parseInt(iimGetExtract()) >= 150)
iimPlay("loop2.iim");
else
iimPlay("Wait.iim");

Get number of elements in Imacros

There are 10 li tags in an html. I need the number to use it with a loop in a vbs file.
I tried this simple code but it didn't work, even in firefox extension
URL GOTO=javascript:document.getElementsByClassName('movableListItem').length;
One can try the code below to set the built-in variable !EXTRACT to the number of image tags in a document. And your question is similar.
SET !EXTRACT_TEST_POPUP NO
URL GOTO=javascript:{window.document.getElementsByTagName("img").length}
URL GOTO=javascript:{window.history.back()}
TAG POS=1 TYPE=HTML ATTR=* EXTRACT=TXT
BACK
Imacros can do it but you need to make a loop and catch the first error. It's kinda complicated for just this simple question but in Selenium IDE just do this:
Command: storeCssCount
Target : css=a
Value : n
And that's all. A single line of code

iMacro cannot save extract value to file

I am trying to save EXTRACT variable data to text file by using iMacro. However, I show the EXTRACT variable with value. Please save this file as .js before you try on iMacros. Thank you.
Show EXTRACT variable value.
iimSet("EXTRACT", "abcde");
iimPlay("CODE: PROMPT {{EXTRACT}}");
Save EXTRACT variable value to abc.txt.
scmd = "CODE:SAVEAS TYPE=EXTRACT FOLDER=/Users/user1/iMacros FILE=abc.txt";
iimPlay(scmd);
make it simple,since you are using javascript anyway, use javascript prompt like this
var ask=prompt("Please enter your name");
iimSet("ask",ask);
iimPlay("code: set !extract {{ask}}\nSAVEAS TYPE=EXTRACT FOLDER=/Users/user1/iMacros FILE=abc.txt");