javascriptloopsimacros

loop creation Imacros


I apologize for my English.

I have two JavaScrypt scripts in Imacros. Separately, each one executes its own loop and works without any problems. But for the fifth day in a row I am trying to combine these two scripts into one. to automate this process. but unfortunately I am failing again and again. for this reason I started to study JavaScrypt. my head is spinning.

Script1. It works with links.

var macro;
macro =  "CODE:";
macro +=  "SET !EXTRACT_TEST_POPUP NO" + "\n"; 
macro +=  "SET !ENCRYPTION NO" + "\n"; 
macro +=  "SET !ERRORIGNORE YES" + "\n"; 
macro +=  "'Подключаем наш файл" + "\n"; 
macro +=  "SET !DATASOURCE D:\\iMacros\\Datasources\\Ok\\URLs.csv" + "\n"; 
macro +=  "SET !DATASOURCE_COLUMNS 1" + "\n"; 
macro +=  "'данные с нужной строки" + "\n"; 
macro +=  "SET !DATASOURCE_LINE {{i}}" + "\n";
macro +=  "URL GOTO={{!COL1}}" + "\n"; 
macro +=  "WAIT SECONDS=2" + "\n"; 

for(i=1;i<=34;i++)

{ 
iimSet("i",i)
iimPlay(macro)
}

script2 goes to the link that script1 pulled out.

var macro;
macro =  "CODE:";
macro +=  "FILTER TYPE=IMAGES STATUS=ON" + "\n"; 
macro +=  "TAG POS={{i}} TYPE=A ATTR=CLASS:link__91azp<SP>photo-link__79ad9<SP>__primary__91azp*     EXTRACT=HREF" + "\n"; 
macro +=  "'PROMPT {{!EXTRACT}}" + "\n"; 
macro +=  "TAB OPEN" + "\n"; 
macro +=  "TAB T=2" + "\n"; 
macro +=  "URL GOTO={{!EXTRACT}}" + "\n"; 
macro +=  "WAIT SECONDS=5" + "\n"; 
macro +=  "EVENT TYPE=KEYPRESS SELECTOR=* KEY=35" + "\n";
macro +=  "WAIT SECONDS=2" + "\n"; 
macro +=  "TAB CLOSE" + "\n"; 
for(i=1;i<=20;i++){ 
iimSet("i",i);
iimPlay(macro);
}
iimPlay(macro)
 

and this script2 visits the profiles of the members of this link. I put 20 people.

As I said both scripts perform their functions well, but only separately. my task is to combine these two scripts into one script. script1 pulled a link - script2 visited 20 people - script1 pulled a second link - script2 visited 20 people and so on.... I would appreciate your help.

The maximum I could come to is that script1 loads the first link of 34 links. script2 visits only 1 person out of 20 people and the cycle starts over again. that is, script1 extracts the second link and script2 visits the second person and so on. And I want everything to be cyclic. i.e. script1 extracted the first link - script2 went through 20 profiles then the cycle starts over again where script1 extracts the second link and script2 continues to visit 20 profiles and so on.....


Solution

  • You need two different macro var names.

    You need two different index variable names.

    Then move your second loop inside the first loop.

    Note that I do not use iMacros, so I can't test this, but looks right.

    // Script1. It works with links.
    var macro1;
    macro1 =  "CODE:";
    macro1 +=  "SET !EXTRACT_TEST_POPUP NO" + "\n"; 
    macro1 +=  "SET !ENCRYPTION NO" + "\n"; 
    macro1 +=  "SET !ERRORIGNORE YES" + "\n"; 
    macro1 +=  "'Подключаем наш файл" + "\n"; 
    macro1 +=  "SET !DATASOURCE D:\\iMacros\\Datasources\\Ok\\URLs.csv" + "\n"; 
    macro1 +=  "SET !DATASOURCE_COLUMNS 1" + "\n"; 
    macro1 +=  "'данные с нужной строки" + "\n"; 
    macro1 +=  "SET !DATASOURCE_LINE {{i}}" + "\n";
    macro1 +=  "URL GOTO={{!COL1}}" + "\n"; 
    macro1 +=  "WAIT SECONDS=2" + "\n"; 
    
    
    // script2 goes to the link that script1 pulled out.
    var macro2;
    macro2 =  "CODE:";
    macro2 +=  "FILTER TYPE=IMAGES STATUS=ON" + "\n"; 
    macro2 +=  "TAG POS={{i}} TYPE=A ATTR=CLASS:link__91azp<SP>photo-link__79ad9<SP>__primary__91azp*     EXTRACT=HREF" + "\n"; 
    macro2 +=  "'PROMPT {{!EXTRACT}}" + "\n"; 
    macro2 +=  "TAB OPEN" + "\n"; 
    macro2 +=  "TAB T=2" + "\n"; 
    macro2 +=  "URL GOTO={{!EXTRACT}}" + "\n"; 
    macro2 +=  "WAIT SECONDS=5" + "\n"; 
    macro2 +=  "EVENT TYPE=KEYPRESS SELECTOR=* KEY=35" + "\n";
    macro2 +=  "WAIT SECONDS=2" + "\n"; 
    macro2 +=  "TAB CLOSE" + "\n"; 
    
    for(i=1;i<=34;i++) { 
      iimSet("i",i)
      iimPlay(macro1)
    
      // I changed i to pos for this loop, since you are using i in the outer loop
      for(pos=1;pos<=20;pos++){ 
        iimSet("i",pos);
        iimPlay(macro2);
      }
    }