Save Extract

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
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
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Save Extract

Post by Trax » Mon Sep 16, 2013 2:07 pm

Hello, I need something like the code below to work :

Code: Select all

var main, ret,;
main=  "CODE:";
main+=  "SET !ERRORIGNORE YES" + "\n";
main+=  "SET !EXTRACT_TEST_POPUP NO" + "\n"; 
main+=  "TAG POS=1 TYPE=TD ATTR=CLASS:qt_av EXTRACT=TXT" + "\n";
main+=  "TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:qt CONTENT={{!EXTRACT}}" + "\n";
main+=  "TAG POS=2 TYPE=TD ATTR=* EXTRACT=TXT" + "\n";
main+=  "TAG POS=3 TYPE=TD ATTR=* EXTRACT=TXT" + "\n";
...
main+=  "SAVEAS TYPE=EXTRACT FOLDER=* FILE=Extract2.csv" + "\n";

while(1) {
    
        ret=iimPlay(main);
		foo = iimGetExtract(1);
        alert(foo);
		  		  }
My problem is that after I call saveas "extract" is reset but I still need to use the first extract later in my script.
Geoffrey
Posts: 12
Joined: Fri May 03, 2013 11:32 pm

Re: Save Extract

Post by Geoffrey » Mon Sep 16, 2013 4:22 pm

Before you SAVEAS could you set a variable to equal Extract, and then set Extract to equal that variable afterwards?
chivracq
Posts: 8790
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Save Extract

Post by chivracq » Mon Sep 16, 2013 4:28 pm

Can't you use one or several Temp Variable(s) to save the Content of the !EXTRACT before it is reset...?

EDIT: Ah-ah!, previous Post with the same idea...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: Save Extract

Post by Trax » Mon Sep 16, 2013 4:38 pm

I tried putting extract in a variable right after it's done however when I call it it's "Undefined".
chivracq
Posts: 8790
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Save Extract

Post by chivracq » Mon Sep 16, 2013 4:44 pm

For some strange reason, you may need 2 Temp Variables like (partly) explained in this Thread:
http://forum.imacros.net/viewtopic.php?f= ... 585#p54304
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: Save Extract

Post by Trax » Mon Sep 16, 2013 5:03 pm

So your suggestion is to use "set eval" inside a script that is already using javascript... I actually did try that but ran into 2 different errors, both were syntax errors that I have no idea how to fix. If anyone actually managed to use set eval inside javascript I would really like to see that code line :)
User avatar
bobis
Posts: 364
Joined: Sat Sep 11, 2010 3:34 pm
Contact:

Re: Save Extract

Post by bobis » Mon Sep 16, 2013 7:43 pm

here is code example

Code: Select all

var main, ret,foo;
main=  "CODE:";
...
main+=  "TAG POS=3 TYPE=TD ATTR=* EXTRACT=TXT" + "\n";
main +=  "set !var1 {{!extract}}" + "\n";
main+=  "SAVEAS TYPE=EXTRACT FOLDER=* FILE=Extract2.csv" + "\n";
main +=  "set !extract {{!var1}}" + "\n";
while(1) {  
ret=iimPlay(main);
foo = iimGetExtract(0);
alert(foo);
}
Get Best iMacros scripts at http://imacrosbot.com/
chivracq
Posts: 8790
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Save Extract

Post by chivracq » Tue Sep 17, 2013 12:29 am

Trax wrote:So your suggestion is to use "set eval" inside a script that is already using javascript...
No, not really, rather that the Firefox Javascript Interpreter seems to have problems initializing iMacros Variables like we saw in the 'SET EVAL' Case I mentioned, and that you need to "transfuse" the Value of one Variable into another one to avoid Runtime Errors.... (Because the EVAL Function within an iim Macro uses the Firefox Javascript Interpreter as well..., from my understanding of the Wiki...)
Trax wrote:I actually did try that but ran into 2 different errors, both were syntax errors that I have no idea how to fix. If anyone actually managed to use set eval inside javascript I would really like to see that code line :)
Doesn't surprises me, because you'd be using Javascript nested within Javascript, I'm not sure that would work...

But Bobis' idea with iimGetExtract() or iimGetLastExtract() is good indeed, especially if it's a Code Example he's already using, you have predefined Functions in iMacros, just use them...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: Save Extract

Post by Trax » Tue Sep 17, 2013 10:18 am

bobis wrote:here is code example

Code: Select all

var main, ret,foo;
main=  "CODE:";
...
main+=  "TAG POS=3 TYPE=TD ATTR=* EXTRACT=TXT" + "\n";
main +=  "set !var1 {{!extract}}" + "\n";
main+=  "SAVEAS TYPE=EXTRACT FOLDER=* FILE=Extract2.csv" + "\n";
main +=  "set !extract {{!var1}}" + "\n";
while(1) {  
ret=iimPlay(main);
foo = iimGetExtract(0);
alert(foo);
}
This works great, thanks, the only problem was a reference error but that was easy to fix by changing iimGetExtract into iimGetLastExtract.

One more thing ... I was wondering if it's possible to add a time stamp on the same row after all the text is extracted, any ideas?

EDIT:

Actually it seems it's quite easy just modified the code into this

Code: Select all

main+=  "set !var1 {{!extract}}" + "\n";
main+=  "ADD !var1 [EXTRACT]{{!NOW:hh:mm:ss}}" + "\n";
main+=  "set !extract {{!var1}}" + "\n";
main+=  "SAVEAS TYPE=EXTRACT FOLDER=* FILE=Extract.csv" + "\n";
main+=  "set !extract {{!var1}}" + "\n";
Now extract also contains the time stamp and by adding "[EXTRACT]" it's written in the next cell on the same row and can also be called with iimGetExtract(2) if needed for some reason.

However the text I want to extract is not always there and it seems that extract.csv increases in size anyway and when text is found I can see that a lot of rows are skipped in extract.csv. I assume that it adds empty cells and now after adding a time stamp some rows only include that obviously. To fix it the easy way would be to write a few conditions so the code would look something like this:

Code: Select all

var main, ret,foo,foo2, save;
main=  "CODE:";
main+=  "SET !ERRORIGNORE YES" + "\n";
main+=  "SET !TIMEOUT_STEP 0" + "\n";
main+=  "TAG POS=1 TYPE=TD ATTR=CLASS:qunatity EXTRACT=TXT" + "\n";
main+=  "TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:qt CONTENT={{!EXTRACT}}" + "\n";
main+=  "TAG POS=2 TYPE=TD ATTR=* EXTRACT=TXT" + "\n";
main+=  "TAG POS=3 TYPE=TD ATTR=* EXTRACT=TXT" + "\n";
main+=  "SET !VAR1 {{!EXTRACT}}" + "\n";
main+=  "ADD !VAR! [EXTRACT]{{!NOW:hh:mm:ss}}" + "\n";
main+=  "SET !EXTRACT {{!VAR1}}" + "\n";

save= "CODE:";
save+=   "SET !ERRORIGNORE YES" + "\n";
save+=  "SET !extract {{!var1}}" + "\n"; // ideally here I could set extract to foo
save+=  "SAVEAS TYPE=EXTRACT FOLDER=* FILE=Extract.csv" + "\n";
save+=  "set !extract {{!var1}}" + "\n";


while(1) {  
ret=iimPlay(main);
foo = iimGetLastExtract(1);
alert(foo);
if ( condition is met  ) {
ret=iimPlay(second);
foo2=iimGetLastExtract(0);
alert(foo2);
}
}
But upon calling the new macros everything is reset so how could I set a condition and if it's met save the extract.
Post Reply