I have a .iim iMacros file for extracting text from a website, it looks like this:
SET !DATASOURCE listofurls.csv
SET !DATASOURCE_LINE {{CSV}}
URL GOTO={{!COL1}}
WAIT SECONDS=1
TAG POS=1 TYPE=PRE ATTR=TXT:* EXTRACT=TXT
SET !VAR1 EVAL("var a=\"{{!EXTRACT}}\"; var b=a.indexOf(\"total\"); var c=parseFloat(a.substring((b+9),(b+9+3))); c")
SET !EXTRACT NULL
SET !EXTRACT {{!VAR1}}
SAVEAS TYPE=EXTRACT FOLDER=* FILE=result.csv
It runs good in Play (Loop) mode, but need to automatically run as a loop automatically launching it from a shell script. As a normal .iim file can't be automated as a loop I tried to convert it to iMacros javascript:
var accounts = 10;
for(i = 1; i <= accounts; i++){
iimDisplay("Current loop: "+ i);
var extract;
extract = "CODE:";
extract += "SET !DATASOURCE followersapi.csv" + "\n";
extract += "SET !DATASOURCE_LINE {{CSV}}" + "\n";
extract += "URL GOTO={{!COL1}}" + "\n";
extract += "WAIT SECONDS=2" + "\n";
extract += "TAG POS=1 TYPE=PRE ATTR=TXT:* EXTRACT=TXT" + "\n";
extract += "SET !VAR1 EVAL("var a=\"{{!EXTRACT}}\"; var b=a.indexOf(\"total\"); var c=parseFloat(a.substring((b+9),(b+9+3))); c")" + "\n";
extract += "SET !EXTRACT NULL" + "\n";
extract += "SET !EXTRACT {{!VAR1}}" + "\n";
extract += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=result.csv" + "\n";
iimSet("CSV", i);
iimPlay(extract);
}
I get this error:
SyntaxError: missing ; before statement, line 23 (Error code: -991)
And after some research modified this line it from this:
SET !VAR1 EVAL("var a=\"{{!EXTRACT}}\"; var b=a.indexOf(\"total\"); var c=parseFloat(a.substring((b+9),(b+9+3))); c")
to this:
SET !VAR1 EVAL(\"var a=\'{{!EXTRACT}}\'; var b=a.indexOf(\"total\"); var c=parseFloat(a.substring((b+9),(b+9+3))); c\)
And then I get this error:
wrong format of SET command, line 9 (Error code: 910)
Any ideas on how I could get this working? I also tried to launch the .iim file from a .js file and loop it from there, but then the !LOOP is always 1 and it always reads the first line of the csv.. so it's pretty useless.
Thanks a lot!
Try in this way:
extract += 'SET !VAR1 EVAL("var a=\'{{!EXTRACT}}\'; var b=a.indexOf(\'total\'); var c=parseFloat(a.substring((b+9),(b+9+3))); c")' + "\n";