Set Number of Loops variable an Extract from Page

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.

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.

Set Number of Loops variable an Extract from Page

by chrisko on Sat Mar 12, 2016 7:05 am

Hey Guys,

MY CONFIG:
iMacros 8.9.6 for Firefox
Firefox 45.0
Mac OSX 10.10.5

Have that little Loop for Extracting Text in a CSV.

Code: Select all
var macro_1;
macro_1 ="CODE:";
macro_1 +="TAG POS={{i}} TYPE=DIV ATTR=CLASS:_l3<SP>fsm<SP>fwn<SP>fcg" + "\n";
macro_1 +="ADD !EXTRACT {{!URLCURRENT}}" + "\n";
macro_1 +="TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT" + "\n";
macro_1 +="SAVEAS TYPE=EXTRACT FOLDER=* FILE=*" + "\n";
for (var i=1;i<9;i++)
{
iimSet("i",i)
iimPlay(macro_1)
}


So far its running good. But i have manually to decide how often the loop runs. Has anyone an Idea how to get the Number of Loops i need to extract all possible
Code: Select all
TAG POS={{i}} TYPE=DIV ATTR=CLASS:_l3<SP>fsm<SP>fwn<SP>fcg" + "\n";
on the Page?
MY Config: iMacros 8.9.6 for Firefox; Firefox 45.0; Mac OSX 10.10.5
chrisko
 
Posts: 21
Joined: Fri Mar 04, 2016 6:08 pm

Re: Set Number of Loops variable an Extract from Page

by chivracq on Sat Mar 12, 2016 9:52 am

chrisko wrote:Hey Guys,

MY CONFIG:
iMacros 8.9.6 for Firefox
Firefox 45.0
Mac OSX 10.10.5

Have that little Loop for Extracting Text in a CSV.

Code: Select all
var macro_1;
macro_1 ="CODE:";
macro_1 +="TAG POS={{i}} TYPE=DIV ATTR=CLASS:_l3<SP>fsm<SP>fwn<SP>fcg" + "\n";
macro_1 +="ADD !EXTRACT {{!URLCURRENT}}" + "\n";
macro_1 +="TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT" + "\n";
macro_1 +="SAVEAS TYPE=EXTRACT FOLDER=* FILE=*" + "\n";
for (var i=1;i<9;i++)
{
iimSet("i",i)
iimPlay(macro_1)
}


So far its running good. But i have manually to decide how often the loop runs. Has anyone an Idea how to get the Number of Loops i need to extract all possible
Code: Select all
TAG POS={{i}} TYPE=DIV ATTR=CLASS:_l3<SP>fsm<SP>fwn<SP>fcg" + "\n";
on the Page?

Yep, different Approaches...:
1- After the 'SAVEAS', you include some 'TAG' + 'EXTRACT' on 'POS=i+1' in your Macro and you loop your Macro until it returns '#EANF#' in 'iimGetExtract()'.
2- You first extract (on 'HTM') some higher HTML Element containing all 'DIV' Elements that you want to extract with 'POS=i' and using 'EVAL()' + 'match()' or 'split()' (which I find much more simple to use than 'match()'...), the 'length' Property of the Array returned by 'split()' (minus 1, I would think...) will give you how many times you have to loop your Macro.

And there are probably other ways as well...
One of my ('.iim') Macros runs "once" and decides by itself at the end once it's gathered all Info it needs if it needs to repeat itself and how many times it needs to loop..., but I use a different Technique in pure '.iim', as I don't use '.js' Sccripts.

EDIT: Corrected Typo: 'getExtract()' => 'iimGetExtract()'.
Last edited by chivracq on Sat Mar 12, 2016 5:12 pm, edited 1 time in total.
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 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: 6473
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Set Number of Loops variable an Extract from Page

by chrisko on Sat Mar 12, 2016 4:08 pm

Approach 1... hmm, i tried, but didnt get :-(

Approach 2: Yep, works. Maybe a little complicated:
Code: Select all
iimPlayCode ("URL GOTO=http://url.com")
iimPlayCode ("filedelete name=result.csv")
get_message_text();

function get_message_text() {
   var macro_1;
   var x = get_Loops();
   window.alert(x);
   iimPlayCode ("URL GOTO=http://url.com");   
   macro_1 ="CODE:SET !TIMEOUT_STEP 1"+ "\n";
   macro_1 +="TAG POS={{i}} TYPE=DIV ATTR=CLASS:_l3<SP>fsm<SP>fwn<SP>fcg" + "\n";
   macro_1 +="ADD !EXTRACT {{!URLCURRENT}}" + "\n";
   macro_1 +="TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT" + "\n";
   macro_1 +="SAVEAS TYPE=EXTRACT FOLDER=* FILE=result.csv" + "\n";
   for (var i=1;i<x;i++)
      {
      iimSet("i",i)
      iimPlay(macro_1)
      }
}
function get_Loops() {
   var i = 1;
   var s = "";
   iimPlay("CODE:SET !TIMEOUT_STEP 1");
   while (s !== "#EANF#") {   
       iimSet("i",i)
       iimPlay("CODE:TAG POS={{i}} TYPE=A ATTR=ID:js_* EXTRACT=HREF");      
       s = iimGetLastExtract();
       i++;
      }
   return i-1;
}


hey, the TAG in the loop was my first manually set TAG with the help of Firebug ;-) I think i got the "Tagging" now.
MY Config: iMacros 8.9.6 for Firefox; Firefox 45.0; Mac OSX 10.10.5
chrisko
 
Posts: 21
Joined: Fri Mar 04, 2016 6:08 pm

Re: Set Number of Loops variable an Extract from Page

by chivracq on Sat Mar 12, 2016 5:09 pm

chrisko wrote:Approach 1... hmm, i tried, but didnt get :-(

Approach 2: Yep, works. Maybe a little complicated:
Code: Select all
iimPlayCode ("URL GOTO=http://url.com")
iimPlayCode ("filedelete name=result.csv")
get_message_text();

function get_message_text() {
   var macro_1;
   var x = get_Loops();
   window.alert(x);
   iimPlayCode ("URL GOTO=http://url.com");   
   macro_1 ="CODE:SET !TIMEOUT_STEP 1"+ "\n";
   macro_1 +="TAG POS={{i}} TYPE=DIV ATTR=CLASS:_l3<SP>fsm<SP>fwn<SP>fcg" + "\n";
   macro_1 +="ADD !EXTRACT {{!URLCURRENT}}" + "\n";
   macro_1 +="TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT" + "\n";
   macro_1 +="SAVEAS TYPE=EXTRACT FOLDER=* FILE=result.csv" + "\n";
   for (var i=1;i<x;i++)
      {
      iimSet("i",i)
      iimPlay(macro_1)
      }
}
function get_Loops() {
   var i = 1;
   var s = "";
   iimPlay("CODE:SET !TIMEOUT_STEP 1");
   while (s !== "#EANF#") {   
       iimSet("i",i)
       iimPlay("CODE:TAG POS={{i}} TYPE=A ATTR=ID:js_* EXTRACT=HREF");      
       s = iimGetLastExtract();
       i++;
      }
   return i-1;
}


hey, the TAG in the loop was my first manually set TAG with the help of Firebug ;-) I think i got the "Tagging" now.

Hum, nice Code Sample on Approach 2, especially in '.js'...
Impressed you got that one to work as indeed, Approach 1 should be much more simple to implement... You don't post what you tried, so I can't tell you if I see the Pb..., but it should have been very straightforward, I would think..., if you followed my Advice to put the 'TAG POS=i+1' after the 'SAVEAS' (then '!EXTRACT' gets reset and you get a clean '!EXTRACT' with only if 'POS=i+1' exists and the '.iim' Macro still needs to run at least one more time...).

And recommended by TechSupport is to use 'iimGetExtract()' instead of 'iimGetLastExtract()' which is supposed to be deprecated..., even if both still work... And hum, I realize I made a Typo in the name of the Command..., I am going to correct my previous Msg...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 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: 6473
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Scripting and Command Line Interface

Who is online

Users browsing this forum: No registered users and 6 guests

-->