Getting Data source to Loop

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.

Getting Data source to Loop

by radtad on Thu May 26, 2016 7:32 pm

Trying to get my data source (Step2.csv) to loop to the next line of data...it keeps pulling from line 1 and not heading down the list...

for : var imacros_main32 : I bolded the area I need help with. Thanks

Code: Select all
//
// This imacros script created by 9kw.eu
// Find more here: http://www.9kw.eu/
//
// The script fill the captcha of recaptcha v2 demo.
//
// Note for users with firefox with the message "Firefox prevented this page from automatically reloading.":
// UNCHECK the option "warn me when pages try to redirect" in your browser
// You find the checkbox under Options > Advanced > General > Accessibility
//
// More informations with iMacros for Firefox and speed up javascript: 
// http://wiki.imacros.net/iMacros_for_Firefox#Javascript_Scripting_Interface
//
// You can use more instances with Firefox:
// http://kb.mozillazine.org/Opening_a_new_instance_of_Firefox_with_another_profile
// https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
// http://kb.mozillazine.org/Command_line_arguments
// Like -P "My Profile" -no-remote or -ProfileManager
//
// Path to the captcha image with timestamp
// Tempfolder like C:\ or C:\TEMP\ under windows or like /tmp/ under linux
// In Javascript and windows with escape like C:\\TEMP\\
var tempfolder = 'C:\\TEMP\\';//optional, like C:\\TEMP\\

// Tempslash (Path with slashs as (tempfolder) and with the htmlfile recaptcha_v2.html
var tempslash = "C:/TEMP/";//optional, like C:/TEMP/

// Step 1: Config for 9kw.eu for your apikey
var apikey = "";

//And priority (prio 1-20)
var prio = "1";

// Loops
var max_loop = 1;
var max_wait = "";//seconds, optional

// Url
var myurl = "URL GOTO=https://www.textnow.com/signup";
myurl += "";//extra lines

// Submit
var mysubmit = "TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:NoFormName ATTR=*\n";
mysubmit += "";//extra lines

// Replayspeed
var replayspeed = "FAST";//MEDIUM
var replayspeed_clicks = "FAST";

// Debug
var breakOnError = false;
var onBreakAlert = true;
var logFile = true;
var logFileName = 'iimLog.txt';
var max_loop_limit = 500;

//Performance for recaptchav2 like default 1 + 10 = Frame 11 as start for few functions
var higher_frame_number = 1;//Standard (like 6)
var other_frame_number = 0;//Startframe
var max_frame_number = 15;//Standardframe as max (like 15)
var total_frame_number = 20;//SearchFrame+SearchOK

//header
var imacros_header = "SET !EXTRACT_TEST_POPUP NO\n";
imacros_header += "SET !ERRORIGNORE NO\n";
imacros_header += "SET !TIMEOUT_PAGE 999\n";
imacros_header += "SET !TIMEOUT_STEP 999\n"
imacros_header += "SET !REPLAYSPEED "+replayspeed+"\n";

//Main
var logFilePath = getiMacrosFolder('Logs')+'\\'+logFileName;
var tempfile;

var httpRequestObserver =  { 
  observe: function(subject, topic, data)  { 
    if (topic == "http-on-modify-request") { 
      var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel); 
      if (
         /funcaptcha.com|solvemedia.com|keycaptcha.com|confidenttechnologies.com/.test(httpChannel.originalURI.host) ||
         /google.com\/recaptcha|gstatic.com\/recaptcha/.test(httpChannel.URI.spec)
     
      ) { 
         httpChannel.setRequestHeader("Accept-Language", "en,en-US;de;q=0.5", false); 
      }
    } 
  }, 
 
  get observerService() { 
    return Components.classes["@mozilla.org/observer-service;1"] 
                     .getService(Components.interfaces.nsIObserverService); 
  }, 
 
  register: function() 
  { 
    this.observerService.addObserver(this, "http-on-modify-request", false); 
  }, 
 
  unregister: function() 
  { 
    this.observerService.removeObserver(this, "http-on-modify-request"); 
  } 
};
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(httpRequestObserver, "http-on-modify-request", false);
httpRequestObserver.register();

(function() {
   // Syntaxcheck: API Key, prio
   if(apikey.match(/^[a-zA-Z0-9]+$/) && apikey.length <= 50 && apikey.length >= 5){}else{alert_message("API Key \""+apikey+"\" is wrong.");return false;}
   var d = parseFloat(prio); if(d >= 0 && d <= 20){}else{alert_message("Prio \""+prio+"\" is not in the set range.");return false;}

   // only valid number
   if (/[^\d]/.test(max_loop)) {
      alert_message('Please enter a valid number for loop play');
      return false;
   }
   
   max_loop = parseInt(max_loop);
   if(max_loop > max_loop_limit){
      alert_message('Loop limit exceed (' + max_loop_limit + ') , edit the following variable to use your own limit.\n\nvar max_loop_limit = ' + max_loop_limit + ';');
      return false;
   }   
   
   for(var loop = 1; loop <= max_loop; loop++){
      var function_code = "";
      function_code = recaptchav2();
      if(function_code == false && breakOnError == true){
         return false;
      }
      if (/[\d]/.test(max_wait)) {
         wait(max_wait);
      }
   }
})();

httpRequestObserver.unregister();
observerService.removeObserver(httpRequestObserver, "http-on-modify-request");
//End

// functions
// recaptcha v2
function recaptchav2(){
   var imacros_first = "CODE:"+imacros_header+"TAB CLOSEALLOTHERS\n"
   imacros_first += "TAB T=1\n";
   imacros_first += myurl;
   iimPlay(imacros_first)
   
   // start execution
   var start = new Date(), end; // for benchmarking
   
   // Step 2: Save the captcha picture to local disk
   // initial click macro
   var frame = SearchFrame("EVENT TYPE=CLICK SELECTOR=\"#recaptcha-anchor>DIV:nth-of-type(5)\" BUTTON=0",0);
   iimSet("frame",frame)
   //Wait a random number of seconds
   wait(Math.floor(Math.random()*3 + 1));
   var checkOK;
   var more_correct_solutions;
   var captchaid;
   
   if(/[^\d]/.test(frame) || frame < 1){
      if(logFile){
         log_message("No captcha found as frame number.");
      }
      return false;
   }

   for(var i3=1;i3<=5;i3++){
      captchaid = "";
      tempfile = "captcha_"+tempfile_date()+".jpg";

      // macro for checking captcha checkbox
      var solved = SearchOK("TAG POS=1 TYPE=SPAN ATTR=ID:recaptcha-anchor&&aria-checked:true CONTENT=EVENT:MOUSEOVER",1+other_frame_number,max_frame_number);
      if(solved > 0){
         end =+ new Date();
         if(logFile){
            log_message('Captcha is solved\n\rTime spent: '+Math.floor((end-start)/1000));
         }
         //break;
      }else{
         if(i3 > 1){
            //more_correct_solutions = SearchOK("TAG POS=2 TYPE=DIV ATTR=TXT:Multiple<SP>correct<SP>solutions<SP>required<SP>-<SP>please*&&STYLE: CONTENT=EVENT:MOUSEOVER",0+other_frame_number);
            if(more_correct_solutions < 1){
               checkOK = SearchOK("TAG POS=1 TYPE=SPAN ATTR=ID:recaptcha-anchor&&aria-checked:true CONTENT=EVENT:MOUSEOVER",1+other_frame_number,max_frame_number);
               if(checkOK < 1){
                  iimPlay(imacros_first)
                  wait(3)
                  SearchOK("EVENT TYPE=CLICK SELECTOR=\"#recaptcha-anchor>DIV:nth-of-type(5)\" BUTTON=0",0+other_frame_number);
               }
            }
         }

         var save_image_header = "SET !REPLAYSPEED "+replayspeed+"\n";
         if(tempfolder.length > 3){
            save_image_header = "ONDOWNLOAD FOLDER="+tempfolder+" FILE="+tempfile+" WAIT=YES\n";
         }else{
            save_image_header = "ONDOWNLOAD FOLDER="+getiMacrosFolder("DataSources")+" FILE="+tempfile+" WAIT=YES\n";
         }
         var save_image = save_image_header+"TAG POS=1 TYPE=DIV ATTR=ID:rc-imageselect CONTENT=EVENT:SAVE_ELEMENT_SCREENSHOT";
         frame = SearchFrame(save_image,frame);
         if(frame > 0){
            iimSet("frame",frame)
         }
         //iimDisplay("Frame: "+frame)
         var clickframe = SearchFrame("TAG POS=1 TYPE=IMG ATTR=SRC:https://www.google.com/recaptcha/api2/payload?c=* CONTENT=EVENT:MOUSEOVER",frame,max_frame_number);
         // find the captcha with 10 images and higher
         var find10 = SearchOK("TAG POS=12 TYPE=IMG ATTR=SRC:https://www.google.com/recaptcha/api2/payload?c=* CONTENT=EVENT:MOUSEOVER",clickframe,clickframe);

         // check for the recaptcha with 10 images or find the captcha with 9 images
         var find9;
         if(find10 < 1){
            find9 = SearchOK("TAG POS=9 TYPE=IMG ATTR=SRC:https://www.google.com/recaptcha/api2/payload?c=* CONTENT=EVENT:MOUSEOVER",clickframe,clickframe);
         }
         
         // check for the recaptcha with 9 images or find the captcha with 8 images
         var find8;
         if(find9 < 1){
            find8 = SearchOK("TAG POS=8 TYPE=IMG ATTR=SRC:https://www.google.com/recaptcha/api2/payload?c=* CONTENT=EVENT:MOUSEOVER",clickframe,clickframe);
         }
         // check for the recaptcha with 8 images or find the captcha with enough images like 2 and more
         var find2;
         if(find8 < 1){
            find2 = SearchOK("TAG POS=2 TYPE=IMG ATTR=SRC:https://www.google.com/recaptcha/api2/payload?c=* CONTENT=EVENT:MOUSEOVER",clickframe,clickframe);
         }
         
         // new captcha image with numbers for the captcha service
         if(find10 > 0 || find9 > 0 || find8 > 0 || find2 > 0){
            var recaptcha_v2_error = false;
            
            for(var ihtml=1;ihtml<=2;ihtml++){
               var imacros_main1 = "CODE:";
               imacros_main1 += imacros_header+"TAB OPEN\n";
               imacros_main1 += "TAB T=2\n";
               if(tempslash.length > 0){
                  imacros_main1 += "URL GOTO=file:///"+tempslash+"recaptcha_v2.html?";
               }else{
                  imacros_main1 += "URL GOTO=file:///"+getiMacrosFolder('DataSources').replace(/\\/g, '/')+'/'+"recaptcha_v2.html?";
               }
               if(more_correct_solutions > 0){
                  if(find10 > 0){
                     imacros_main1 += "6";
                  }else if(find9 > 0){
                     imacros_main1 += "7";
                  }else{
                     imacros_main1 += "8";
                  }
               }else{
                  if(find10 > 0){
                     imacros_main1 += "2";
                  }else if(find9 > 0){
                     imacros_main1 += "1";
                  }else{
                     imacros_main1 += "3";
                  }
               }
               if(tempslash.length > 0){
                  imacros_main1 += "=file:///"+tempslash+tempfile+"\n";
               }else{
                  imacros_main1 += "=file:///"+getiMacrosFolder('DataSources').replace(/\\/g, '/')+'/'+tempfile+"\n";
               }
               imacros_main1 += "WAIT SECONDS=1\n";
               iimPlay(imacros_main1)
               
               var html_ok = SearchOK("TAG POS=1 TYPE=DIV ATTR=CLASS:c CONTENT=EVENT:MOUSEOVER",0,0);
               if(html_ok > 0){
                  var imacros_main1a;
                  if(tempfolder.length > 3){
                     imacros_main1a = "CODE:"+imacros_header+save_image_header+"FILEDELETE NAME="+tempfolder+tempfile+"\n";            
                  }else{
                     imacros_main1a = "CODE:"+imacros_header+save_image_header+"FILEDELETE NAME="+getiMacrosFolder("DataSources")+'\\'+tempfile+"\n";                           
                  }
                  imacros_main1a += "TAG POS=1 TYPE=DIV ATTR=* CONTENT=EVENT:SAVE_ELEMENT_SCREENSHOT\n";
                  imacros_main1a += "WAIT SECONDS=3\n";
                  imacros_main1a += "TAB CLOSE\n";
                  iimPlay(imacros_main1a)
                  break;
               }else{
                  if(ihtml == 1){
                     iimPlay("CODE:");
                     var imacros_main1b = "CODE:URL GOTO=http://www.9kw.eu/grafik/api/recaptcha_v2.html\n";
                     imacros_main1b += "WAIT SECONDS=1\n";
                     imacros_main1b += "TAG POS=1 TYPE=HTML ATTR=* EXTRACT=HTM\nSAVEAS TYPE=HTM FOLDER=\""+getiMacrosFolder('DataSources')+"\" FILE=recaptcha_v2.html\n";
                     imacros_main1b += "WAIT SECONDS=1\n";
                     imacros_main1b += "TAB CLOSE\n";
                     iimPlay(imacros_main1b)
                  }else{
                     alert_message("No recaptcha_v2.html found on your local browser. Please check it.");
                     recaptcha_v2_error = true;
                     break;
                  }
               }
            }
            if(recaptcha_v2_error){
               if(breakOnError){
                  return false;
               }else{
                  break;
               }               
            }
         }
            
         //Step 3: Open a new tab, and go to 9kw.eu, and submit the captcha picture
         var imacros_main2 = "CODE:"+imacros_header;
         imacros_main2 += "TAB OPEN\n";
         imacros_main2 += "TAB T=2\n";
         imacros_main2 += "URL GOTO=http://www.9kw.eu/grafik/form.html\n";
         //The apikey is used to identify each of our customers, which you can get from the our page. It is assigned to the CONTENT.
         imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:apikey CONTENT="+apikey+"\n";
         //Priority in our system like min. 0 to max. 20 (cost +0-20)
         imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:prio CONTENT="+prio+"\n";
         //Options for the form. See more under http://www.9kw.eu/grafik/form.html and http://www.9kw.eu/api.html
         imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:selfsolve CONTENT=NO\n";
         imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:confirm CONTENT=NO\n";
         imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:case-sensitive CONTENT=NO\n";
         imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:nomd5 CONTENT=YES\n";
         //We need only numbers for this captcha
         if(find10 > 0 || find9 > 0 || find8 > 0 || find2 > 0){
            imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:numeric CONTENT=YES\n";
         }
         imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:source CONTENT=imacros\n";
         // recaptcha v2 for non text captcha or recaptcha for text captcha
         if(find10 > 0 || find9 > 0 || find8 > 0 || find2 > 0){
            imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:oldsource CONTENT=recaptchav2\n";
         }else{
            imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:oldsource CONTENT=recaptcha\n";
         }
         //The path of the captcha picture saved is assigned to the CONTENT
         if(tempfolder.length > 0){
            imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:file-upload-01 CONTENT="+tempfolder+tempfile+"\n";
         }else{
            imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:file-upload-01 CONTENT="+getiMacrosFolder('DataSources')+'\\'+tempfile+"\n";
         }
         //Submit the formdata to 9kw.eu
         imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=TYPE:submit\n";
         //Clean the !EXTRACT variable for the next task
         imacros_main2 += "SET !EXTRACT NULL\n";
         //Extract the characters that are recoginzed from the picture of captcha.
         imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:result EXTRACT=TXT\n";
         iimPlay(imacros_main2)
         var answer = iimGetLastExtract();
         //Step 4: Check the captcha answer (text or nothing like #EANF# = Extraction Anchor Not Found)
         if(answer == "#EANF#" || answer == "ERROR NO USER"){
            answer = "";
         }
         
         //Extract the captchaid from your captcha submit
         var imacros_main3 = "CODE:";
         imacros_main3 += "SET !EXTRACT NULL\n";
         imacros_main3 += "TAG POS=1 TYPE=INPUT ATTR=NAME:captchaid EXTRACT=TXT\n";
         imacros_main3 += "SET captchaid {{!EXTRACT}}\n";
         imacros_main3 += "TAB CLOSE\n";
         imacros_main3 += "FRAME F={{frame}}\n";
         iimPlay(imacros_main3)
         captchaid = iimGetLastExtract();
         
         //Clean the !EXTRACT variable for the next task
         var imacros_main4 = "SET !EXTRACT NULL\n";
         iimPlay(imacros_main4)
         
         //Display extracted data (only for debug)
         //iimDisplay("captchaid: "+captchaid+"\nanswer: "+answer)
         
         //Step 5: Fill the recognized characters to the verification box (Click the pictures 1..16)
         if(find10 > 0 || find9 > 0 || find8 > 0 || find2 > 0){
            var nothing = 0;
            var myarray = answer.split('');
            if(myarray.length < 2){
               alert_message("No answer found. Check the history on 9kw.eu!");
               if(breakOnError){
                  return false;
               }else{
                  break;
               }
            }else{
               for(var i = 0;i < myarray.length; i++){
                  if(myarray[i].match(/^[0-9]+$/)){
                     if(find10 > 0){
                        var two_values;
                        if(myarray[i+1].match(/^[0-9]+$/)){
                           two_values = myarray[i]+myarray[i+1];
                        }else{
                           two_values = myarray[i];
                        }
                        i += 1;
                        two_values = two_values.replace("0", "");
                        nothing += SearchOK("SET !REPLAYSPEED "+replayspeed_clicks+"\nTAG POS="+two_values+" TYPE=IMG ATTR=SRC:https://www.google.com/recaptcha/api2/payload?c=*",1+higher_frame_number,max_frame_number);
                     }else{
                        nothing += SearchOK("SET !REPLAYSPEED "+replayspeed_clicks+"\nTAG POS="+myarray[i]+" TYPE=IMG ATTR=SRC:https://www.google.com/recaptcha/api2/payload?c=*",1+higher_frame_number,max_frame_number);
                     }
                  }
               }
               if(nothing < 2){
                  alert_message("Not enough clicks are possible. Check the min/max frame number.");
                  if(breakOnError){
                     return false;
                  }else{
                     break;
                  }
               }
            }
         }else{//text captcha
            SearchFrame("TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:default-response CONTENT="+answer,0+other_frame_number,max_frame_number);            
         }
            
         //Click the Verify button
         if(find10 > 0 || find9 > 0 || find8 > 0 || find2 > 0){
            SearchFrame("EVENT TYPE=CLICK SELECTOR=\"HTML>BODY>DIV>DIV>DIV:nth-of-type(3)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(2)>DIV\" BUTTON=0",0+other_frame_number,max_frame_number);
         }else{
            SearchFrame("TAG POS=1 TYPE=DIV ATTR=ID:recaptcha-verify-button",0+other_frame_number,max_frame_number);         
         }
      }
      wait(1)
      var solved_check = SearchOK("TAG POS=1 TYPE=SPAN ATTR=ID:recaptcha-anchor&&aria-checked:true CONTENT=EVENT:MOUSEOVER",1+other_frame_number,max_frame_number);
         
      // Submit
      if(solved_check > 0){
         SearchFrame(mysubmit,0+other_frame_number);
      }else{
         more_correct_solutions = SearchOK("TAG POS=2 TYPE=DIV ATTR=TXT:Multiple<SP>correct<SP>solutions<SP>required<SP>-<SP>please*&&STYLE: CONTENT=EVENT:MOUSEOVER",0+other_frame_number);
      }
      
      var imacros_main31 = "CODE:"+imacros_header;{
         imacros_main31 += "CLEAR\n";
         imacros_main31 += "SET !ERRORIGNORE YES\n";
         imacros_main31 += "SET !DATASOURCE C:\\Log\\Step2.csv\n";
         imacros_main31 += "SET !LOOP 1\n";
         imacros_main31 += "SET !DATASOURCE_LINE {{loop}}\n";
         imacros_main31 += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:userForm ATTR=TYPE:text&&NG-FOCUS-ASYNC:movePlaceholder($event);clearErrors(userForm.firstname);&&NG-MAXLENGTH:42&&ID:first&&REQUIRED:&&NG-MODEL:user.first_name* CONTENT={{!COL1}}\n";
         imacros_main31 += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:userForm ATTR=TYPE:text&&NG-FOCUS-ASYNC:movePlaceholder($event);clearErrors(userForm.lastname);&&NG-MAXLENGTH:42&&NG-REQUIRED:true&&NG-MODEL:user.last_name* CONTENT={{!COL2}}\n";
         imacros_main31 += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:userForm ATTR=TYPE:text&&NG-FOCUS-ASYNC:movePlaceholder($event);clearErrors(userForm.username);&&NG-PATTERN:/^(?![0-9]*$)[a-zA-Z0-9_][a-zA-Z0-9_.]*[a-zA-Z0-9_]$/&&ON-BLURS:username* CONTENT={{!COL3}}\n";
         imacros_main31 += "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:userForm ATTR=TYPE:password* CONTENT={{!COL4}}\n";
         imacros_main31 += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:userForm ATTR=TYPE:text&&NG-FOCUS-ASYNC:movePlaceholder($event);<SP>clearErrors(userForm.email)* CONTENT={{!COL5}}\n";
         imacros_main31 += "TAG POS=1 TYPE=BUTTON FORM=NAME:userForm ATTR=CLASS:btn<SP>btn-primary<SP>btnFullWidth<SP>standardBtn<SP>ng-binding&&TYPE:submit&&NG-HIDE:processing\n";
         imacros_main31 += "WAIT SECONDS=13\n";
         iimPlay(imacros_main31)
         }
         
         var imacros_main32 = "CODE:"+imacros_header;{
         imacros_main31 += "!TIMEOUT_STEP 3" + "\n";
         imacros_main32 += "WAIT SECONDS=1\n";
         imacros_main32 += "TAG POS=1 TYPE=A ATTR=CLASS:btn-primary<SP>unlocked-button\n"
         imacros_main32 += "WAIT SECONDS=2\n";
         imacros_main32 += "EVENT TYPE=CLICK SELECTOR=\"#areacode\" BUTTON=0\n"
         imacros_main32 += "EVENTS TYPE=KEYPRESS SELECTOR=\"#areacode\" CHARS=\"815\"\n";
         imacros_main32 += "WAIT SECONDS=2\n";
         imacros_main32 += "EVENT TYPE=CLICK SELECTOR=\"#enterAreaCodeForm>DIV:nth-of-type(2)>INPUT\" BUTTON=0\n";
         imacros_main32 += "WAIT SECONDS=3\n";
         imacros_main32 += "EVENT TYPE=CLICK SELECTOR=\"#fb-close-button\" BUTTON=0\n";
         imacros_main32 += "WAIT SECONDS=1\n";
         iimPlay(imacros_main32)
         }
         
      
      //Step 6: Check and send the captcha feedback back to the captcha service (OK:1, NotOK:2, EN: Right/False, DE: Richtig/Falsch)
      var htmlcode = "";
      if(captchaid.length > 0){
         if(solved_check > 0){
            var imacros_main4b = "CODE:TAG POS=1 TYPE=DIV ATTR=CLASS:recaptcha-success EXTRACT=TXT\n";
            iimPlay(imacros_main4b)
            htmlcode = iimGetLastExtract();
         }
      }
                  
      var feedback;
      if(htmlcode.match(/Juhu/) || htmlcode.match(/Hooray/) || solved_check > 0 || more_correct_solutions < 1){
         feedback = 1;
      }else{
         feedback = 2;
      }
         
      if(captchaid.length > 0){
         var imacros_main5 = "CODE:TAB OPEN\n";
         imacros_main5 += "TAB T=2\n";
         imacros_main5 += "URL GOTO=http://www.9kw.eu/index.cgi?source=imacros&action=usercaptchacorrectback&apikey="+apikey+"&correct="+feedback+"&id="+captchaid+"\n";
         imacros_main5 += "TAB CLOSE\n";
         iimPlay(imacros_main5)
         
         // Cleanup: Delete the old captcha picture
         if(tempfolder.length > 0){
            iimPlay("CODE:"+imacros_header+"SET !ERRORIGNORE YES\nFILEDELETE NAME="+tempfolder+tempfile+"\n");
         }else{
            iimPlay("CODE:"+imacros_header+"SET !ERRORIGNORE YES\nFILEDELETE NAME="+getiMacrosFolder('Downloads')+tempfile+"\n");
         }
      }
      if(feedback == "1"){
         break;
      }
   }
   return;
}


// random between 1 and 9
function rand(){
   return Math.floor(Math.random()*9) + 1;
}

// wait function like wait(2) for two seconds
function wait(waittime){
   iimPlay("CODE: WAIT SECONDS="+waittime+"\n");
   return;
}

// wait function like wait(2) for two seconds
function getextract(shortcode){
   iimPlay("CODE: "+shortcode);
   return iimGetLastExtract();
}

// date functione
function tempfile_date() {
   now = new Date();
   year = "" + now.getFullYear();
   month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
   day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
   hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
   minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
   second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
   return year + month + day + "_" + hour + minute + second;
}

// find frame with true or false as return
function SearchOK(checkcode,firstframenumber,lastframenumber){
   var check = "CODE:"+"SET !REPLAYSPEED "+replayspeed+"\n";
   check += "SET !ERRORIGNORE YES" + "\n";
   check += "SET !TIMEOUT_STEP 0" + "\n";
   check += "FRAME F={{i}}" + "\n";
   check += "SET !ERRORIGNORE NO" + "\n";
         
   if (checkcode != ""){
      check += checkcode + "\n";
   }else{
      return 0;
   }
      
   if(/^\d+$/.test(firstframenumber)) {
      frame = firstframenumber;
   }else{
      frame = 1;
   }
   
   if(/^\d+$/.test(lastframenumber)) {
      frame2 = lastframenumber;
   }else{
      frame2 = total_frame_number;
   }

   for(var i=frame;i<=frame2;i++){
      iimSet("i",i)

      if(iimPlay(check) == true){
         return 1;
      }
   }
   return 0;
}

// find frame with the framenumber as return
function SearchFrame(checkcode,firstframenumber){
   var check = "CODE:"+"SET !REPLAYSPEED "+replayspeed+"\n";
   check += "SET !ERRORIGNORE YES" + "\n";
   check += "SET !TIMEOUT_STEP 0" + "\n";
   check += "FRAME F={{i}}" + "\n";
   check += "SET !ERRORIGNORE NO" + "\n";
         
   if (checkcode != ""){
      check += checkcode + "\n";
   }else{
      return 0;
   }
      
   if(/^\d+$/.test(firstframenumber)) {
      frame = firstframenumber;
   }else{
      frame = 1;
   }

   for(var i=frame;i<=total_frame_number;i++){
      iimSet("i",i)

      //if the result of the macro is true save frame number and break
      if(iimPlay(check) == true){
         frame = i;
         break;
      }
   }
   //return frame number
   return frame;
}

// Get the imacros folder
function getiMacrosFolder(folderName){
   var pname;
   switch (folderName){
      case "Macros" :
         pname = "defsavepath";
         break;
      case "DataSources" :
         pname = "defdatapath";
         break;
      case "Downloads" :
         pname = "defdownpath";
         break;
      case "Logs" :
         pname = "deflogpath";
         break;
      default :
         throw folderName + " is not a valid iMacros folder name";
         break;
   }
   return imns.Pref.getFilePref(pname).path;
}

// Logfunction
function log_message(msg) {
   var time = new Date().toString().replace(/\s+GMT.*/, '');
   msg = time + ' - ' + msg + '\n';
   var file_o = imns.FIO.openNode(logFilePath);
   imns.FIO.appendTextFile(file_o, msg);
}

// Logfunction
function alert_message(msg){
   if(logFile){
      log_message(msg);
   }

   iimDisplay(msg);

   if(onBreakAlert){
      alert(msg);
   }
}




var imacros_main31 = "CODE:"+imacros_header;{
imacros_main31 += "CLEAR\n";
imacros_main31 += "SET !ERRORIGNORE YES\n";
imacros_main31 += "SET !DATASOURCE C:\\Log\\Step2.csv\n";
imacros_main31 += "SET !LOOP 1\n";
imacros_main31 += "SET !DATASOURCE_LINE {{loop}}\n";

imacros_main31 += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:userForm ATTR=TYPE:text&&NG-FOCUS-ASYNC:movePlaceholder($event);clearErrors(userForm.firstname);&&NG-MAXLENGTH:42&&ID:first&&REQUIRED:&&NG-MODEL:user.first_name* CONTENT={{!COL1}}\n";
imacros_main31 += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:userForm ATTR=TYPE:text&&NG-FOCUS-ASYNC:movePlaceholder($event);clearErrors(userForm.lastname);&&NG-MAXLENGTH:42&&NG-REQUIRED:true&&NG-MODEL:user.last_name* CONTENT={{!COL2}}\n";
imacros_main31 += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:userForm ATTR=TYPE:text&&NG-FOCUS-ASYNC:movePlaceholder($event);clearErrors(userForm.username);&&NG-PATTERN:/^(?![0-9]*$)[a-zA-Z0-9_][a-zA-Z0-9_.]*[a-zA-Z0-9_]$/&&ON-BLURS:username* CONTENT={{!COL3}}\n";
imacros_main31 += "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:userForm ATTR=TYPE:password* CONTENT={{!COL4}}\n";
imacros_main31 += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:userForm ATTR=TYPE:text&&NG-FOCUS-ASYNC:movePlaceholder($event);<SP>clearErrors(userForm.email)* CONTENT={{!COL5}}\n";
imacros_main31 += "TAG POS=1 TYPE=BUTTON FORM=NAME:userForm ATTR=CLASS:btn<SP>btn-primary<SP>btnFullWidth<SP>standardBtn<SP>ng-binding&&TYPE:submit&&NG-HIDE:processing\n";
imacros_main31 += "WAIT SECONDS=13\n";
iimPlay(imacros_main31)
}
radtad
 
Posts: 6
Joined: Tue May 26, 2015 3:59 pm

Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 5 guests

-->