iimGetLastExtract() doens't work

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

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.

iimGetLastExtract() doens't work

by Lafayette on Sun Jun 25, 2017 4:44 am

Hello,

My desktop is GNU/Linux debian testing, Firefox 45.9.0 and iMacros for Firefox 8.9.7.

I'm new in Imacros and I'm trying to extract -as a trainning- the data from a table on a website and different tabs. I have encountered a problem with EXTRACT command combined with iimGetLastExtract(n).

The code can extract (PROMPT {{!EXTRACT}} show value) data and save in .csv file, but iimGetLastExtract(n) only read null value for all data extracted, and the javascript logical operator's code doens't work. But, if I insert SET !EXTRACTDIALOG YES javascript works fine but doens't save data in .csv file.

Code: Select all
// Carga del website
var macro1 = "CODE:";
macro1 += "TAB T=1\n";
macro1 += "URL GOTO=http://es.global-rates.com/estadisticas-economicas/inflacion/indice-de-precios-al-consumo/ipc/ipc.aspx\n";
macro1 += "SET !TIMEOUT_STEP 1\n";

// Extracción de datos   
var macro2 = "CODE:";
macro2 += "SET !TIMEOUT_STEP 1\n";
macro2 += "TAG POS=1 TYPE=TD ATTR=TXT:{{i}} EXTRACT=TXT\n";
macro2 += "TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT\n";
macro2 += "TAG POS=R2 TYPE=TD ATTR=TXT:* EXTRACT=TXT\n";
macro2 += "SET !EXTRACTDIALOG YES\n";
macro2 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=VISORD_o.csv\n";

// Ir a nueva URL   
var macro3 = "CODE:";
macro3 += "TAB OPEN NEW\n";
macro3 += "TAB T=2\n";
macro3 += "URL GOTO=http://www.google.com \n";
macro3 += "TAG POS=2 TYPE=DIV ATTR=TXT:Google.es* EXTRACT=TXT\n";
macro3 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=VISORD_o.csv\n";
macro3 += "TAB T=1\n";
macro3 += "TAB CLOSEALLOTHERS\n";

for (l=1;l<2;l++)
{
   iimPlay(macro1);
   
   for (n=1;n<8;n++)
   {
      var i = ["Alemania","Austria","Brasil","Corea del Sur","Dimamarca","Eslovaquia","Japón"];      
      iimSet("i",i[n-1]);
      iimPlay(macro2);
      var date = iimGetLastExtract(2);
      //alert(date);
      if (date == 'mayo 2017')
      {
         iimPlay(macro3);
      }
   }
}

I have read the FAQ's and SET !EXTRACTDIALOG YES is not supported by Firefox.

Would someone be able to have a look at this and see what I'm doing wrong? Many thanks for your time and efforts.
Lafayette
 
Posts: 6
Joined: Sun Jun 25, 2017 12:19 am

Re: iimGetLastExtract() doens't work

by chivracq on Sun Jun 25, 2017 1:04 pm

Lafayette wrote:Hello,

My desktop is
Code: Select all
GNU/Linux debian testing, Firefox 45.9.0 and iMacros for Firefox 8.9.7.


I'm new in Imacros and I'm trying to extract -as a trainning- the data from a table on a website and different tabs. I have encountered a problem with EXTRACT command combined with iimGetLastExtract(n).

The code can extract (PROMPT {{!EXTRACT}} show value) data and save in .csv file, but iimGetLastExtract(n) only read null value for all data extracted, and the javascript logical operator's code doens't work. But, if I insert SET !EXTRACTDIALOG YES javascript works fine but doens't save data in .csv file.

Code: Select all
// Carga del website
var macro1 = "CODE:";
macro1 += "TAB T=1\n";
macro1 += "URL GOTO=http://es.global-rates.com/estadisticas-economicas/inflacion/indice-de-precios-al-consumo/ipc/ipc.aspx\n";
macro1 += "SET !TIMEOUT_STEP 1\n";

// Extracción de datos   
var macro2 = "CODE:";
macro2 += "SET !TIMEOUT_STEP 1\n";
macro2 += "TAG POS=1 TYPE=TD ATTR=TXT:{{i}} EXTRACT=TXT\n";
macro2 += "TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT\n";
macro2 += "TAG POS=R2 TYPE=TD ATTR=TXT:* EXTRACT=TXT\n";
macro2 += "SET !EXTRACTDIALOG YES\n";
macro2 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=VISORD_o.csv\n";

// Ir a nueva URL   
var macro3 = "CODE:";
macro3 += "TAB OPEN NEW\n";
macro3 += "TAB T=2\n";
macro3 += "URL GOTO=http://www.google.com \n";
macro3 += "TAG POS=2 TYPE=DIV ATTR=TXT:Google.es* EXTRACT=TXT\n";
macro3 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=VISORD_o.csv\n";
macro3 += "TAB T=1\n";
macro3 += "TAB CLOSEALLOTHERS\n";

for (l=1;l<2;l++)
{
   iimPlay(macro1);
   
   for (n=1;n<8;n++)
   {
      var i = ["Alemania","Austria","Brasil","Corea del Sur","Dimamarca","Eslovaquia","Japón"];      
      iimSet("i",i[n-1]);
      iimPlay(macro2);
      var date = iimGetLastExtract(2);
      //alert(date);
      if (date == 'mayo 2017')
      {
         iimPlay(macro3);
      }
   }
}

I have read the FAQ's and SET !EXTRACTDIALOG YES is not supported by Firefox.

Would someone be able to have a look at this and see what I'm doing wrong? Many thanks for your time and efforts.

Ah-ah...!, you got me puzzled for a few seconds, ah-ah...! But yep, normal..., the 'SAVEAS' actually resets the Content of the '!EXTRACT' Var, so if you want to "reuse" it after the 'SAVEAS', for your 'iimGet(Last)Extract()' for example, you then need to "secure" it in some Temp Var...:
Code: Select all
TAG POS=1 TYPE=TD ATTR=TXT:{{i}} EXTRACT=TXT
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT
TAG POS=R2 TYPE=TD ATTR=TXT:* EXTRACT=TXT

'Secure '!EXTRACT' Content in some Temp Var before the 'SAVEAS':
SET Temp_EXTRACT {{!EXTRACT}}
SAVEAS TYPE=EXTRACT FOLDER=* FILE=VISORD_o.csv
SET !EXTRACT {{Temp_EXTRACT}}
- (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: iimGetLastExtract() doens't work

by Lafayette on Fri Jul 07, 2017 2:47 pm

With delay and apologies, I show you a couple of solutions to be able to print the data extraction.



A solution with iimSet ("value", value) sending it to a ADD! EXTRACT {{value}} \ n ";

Code: Select all
// macro1 += "\n";
// Carga del website
var macro1 = "CODE:";
macro1 += "TAB T=1\n";
macro1 += "URL GOTO=http://es.global-rates.com/estadisticas-economicas/inflacion/indice-de-precios-al-consumo/ipc/ipc.aspx\n";
macro1 += "SET !TIMEOUT_STEP 1\n";

// Extracción de datos   
var macro2 = "CODE:";
macro2 += "SET !TIMEOUT_STEP 1\n";
macro2 += "TAG POS=1 TYPE=TD ATTR=TXT:{{i}} EXTRACT=TXT\n";
macro2 += "TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT\n";
macro2 += "TAG POS=R2 TYPE=TD ATTR=TXT:* EXTRACT=TXT\n";

// Ir a nueva URL   
var macro3 = "CODE:";
macro3 += "TAB OPEN NEW\n";
macro3 += "TAB T=2\n";
macro3 += "URL GOTO=http://www.google.com/\n";
macro3 += "TAG POS=2 TYPE=DIV ATTR=TXT:Google.es* EXTRACT=TXT\n";
macro3 += "TAB T=1\n";
macro3 += "TAB CLOSEALLOTHERS\n";

// Salvar los datos encontrados   
var macro4 = "CODE:";
macro4 += "ADD !EXTRACT {{country}}\n";
macro4 += "ADD !EXTRACT {{date}}\n";
macro4 += "ADD !EXTRACT {{value}}\n";
macro4 += "ADD !EXTRACT {{goo}}\n";
macro4 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=Inflacion1.csv\n";

for (l=1;l<3;l++)
{
   iimPlay(macro1);
   
   for (n=1;n<8;n++)
   {
      var i = ["Alemania","Austria","Brasil","Corea del Sur","Dimamarca","Eslovaquia","Japón"];      
      iimSet("i",i[n-1]);
      iimPlay(macro2);
      
      var country = iimGetLastExtract(1);
      var date = iimGetLastExtract(2);
      var value = iimGetLastExtract(3);
      
      if (date == 'mayo 2017')
      {
         iimPlay(macro3);
         var goo = iimGetLastExtract(1);
         iimSet("country",country);
         iimSet("date",date);
         iimSet("value",value);
         iimSet("goo",goo);
         iimPlay(macro4);
      }
      /*else{
         iimSet("country",country);
         iimSet("date",date);
         iimSet("value",value);
         iimSet("goo",goo);
         iimPlay(macro4);
      }*/
   }
}




And another solution with an array, cleaning it every loop.

Code: Select all
// macro1 += "\n";
// Carga del website
var macro1 = "CODE:";
macro1 += "TAB T=1\n";
macro1 += "URL GOTO=http://es.global-rates.com/estadisticas-economicas/inflacion/indice-de-precios-al-consumo/ipc/ipc.aspx\n";
macro1 += "SET !TIMEOUT_STEP 1\n";

// Extracción de datos   
var macro2 = "CODE:";
macro2 += "SET !TIMEOUT_STEP 1\n";
macro2 += "TAG POS=1 TYPE=TD ATTR=TXT:{{i}} EXTRACT=TXT\n";
macro2 += "TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT\n";
macro2 += "TAG POS=R2 TYPE=TD ATTR=TXT:* EXTRACT=TXT\n";

// Ir a nueva URL   
var macro3 = "CODE:";
macro3 += "TAB OPEN NEW\n";
macro3 += "TAB T=2\n";
macro3 += "URL GOTO=http://www.google.com/\n";
macro3 += "TAG POS=2 TYPE=DIV ATTR=TXT:Google.es* EXTRACT=TXT\n";
macro3 += "TAB T=1\n";
macro3 += "TAB CLOSEALLOTHERS\n";

// Salvar los datos encontrados   
var macro4 = "CODE:";
macro4 += "ADD !EXTRACT {{1}}\n";
macro4 += "ADD !EXTRACT {{2}}\n";
macro4 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=inflacion2.csv\n";


var impresion = new Array();

for (l=1;l<10;l++)
{
   iimPlay(macro1);
   
   for (n=1;n<3;n++)
   {
      var i = ["Alemania","Austria","Brasil","Corea del Sur","Dimamarca","Eslovaquia","Japón"];      
      iimSet("i",i[n-1]);
      iimPlay(macro2);
      
      var country = iimGetLastExtract(1);
      impresion[1] = country;
      var date = iimGetLastExtract(2);
      var value = iimGetLastExtract(3);
      
      if (date == 'mayo 2017')
      {
         iimPlay(macro3);
         var goo = iimGetLastExtract(1);
         impresion[2] = goo;
         iimSet("country",country);
         iimSet("date",date);
         iimSet("value",value);
         iimSet("goo",goo);
         //iimPlay(macro4);
      }
      alert("Muestro array 1: "+impresion[1]);
      alert("Muestro array 1: "+impresion[2]);
      iimSet("1",impresion[1]);
      iimSet("2",impresion[2]);      
      iimPlay(macro4);
      impresion = [];
      /*else{
         iimSet("country",country);
         iimSet("date",date);
         iimSet("value",value);
         iimSet("goo",goo);
         iimPlay(macro4);
      }*/
   }
}

Lafayette
 
Posts: 6
Joined: Sun Jun 25, 2017 12:19 am


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 2 guests

-->