Help to loop for specific times and not infinite

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
frankhack1
Posts: 83
Joined: Fri Mar 20, 2009 9:12 pm

Help to loop for specific times and not infinite

Post by frankhack1 » Tue May 13, 2014 8:10 pm

Hi !

Where do I have to change to tell the macros to loop 200 times and not infinite?

Code: Select all

var a, timeOut, playStatus, macro;
var en = "\n";

a = 1;
while (a <= 1) {
	macro =  "CODE:";
	macro +=  "TAB T=1" + "\n"; 
	macro +=  "CLEAR" + "\n"; 
	macro +=  "URL GOTO=http://www.idealista.com/alquiler-viviendas/barcelona/eixample/la-sagrada-familia/" + "\n"; 
	macro +=  "TAG POS=1 TYPE=SPAN ATTR=CLASS:h1aux EXTRACT=TXT" + "\n";
	macro +=  "TAG POS=1 TYPE=LI ATTR=ID:*&&CLASS:adv*" + "\n"; 
	playStatus = iimPlay(macro)
	if (playStatus >= 1) {
		a++;
	}
	else {
		iimDisplay("Website time out, reloading...");
		a = 1;
	}
};
var extracted = iimGetLastExtract();
var del1 = iimGetLastExtract().replace(": ","");
var del2 = del1.replace("anuncios","");
var totalPage = del2;

a = 1;
while (a <= totalPage) {
	macro =  "CODE:";
	macro +=  "TAB T=1" + "\n"; 
	macro +=  "TAG POS=1 TYPE=DIV ATTR=CLASS:advertiser-data<SP>txt-soft EXTRACT=TXT" + "\n"; 
	var advertiserData = iimPlay(macro)
	var data = iimGetLastExtract();
	var searchParticular = /particular/i;
	var ifParticular = searchParticular.test(data);
	macro =  "CODE:";
	macro +=  "TAB T=1" + "\n"; 
	macro +=  "SET !TIMEOUT_STEP 2" +en;
	macro +=  "TAG POS=1 TYPE=DIV ATTR=CLASS:about-advertiser" + "\n"; 
	var advert = iimPlay(macro)
	if (ifParticular == true && advert <= 1) {
		iimDisplay("The URL will be extracted. Saving to C:urls.csv")
		macro =  "CODE:";
		macro +=  "TAB T=1" + "\n"; 
		macro +=  "SET !EXTRACTADD {{!URLCURRENT}}" + "\n"; 
		macro +=  "SAVEAS TYPE=EXTRACT FOLDER=C:\ FILE=urls.csv" + "\n"; 
		playStatus = iimPlay(macro)

		iimDisplay("Saving complete.")
		macro =  "CODE:";
		macro +=  "TAB T=1" + "\n"; 
		macro +=  "TAG POS=1 TYPE=SPAN ATTR=TXT:siguiente" + "\n"; 
		iimPlay(macro)
		a++;
	}
	else {
		iimDisplay("The URL will not be Extracted. Next page...")
		macro =  "CODE:";
		macro +=  "TAB T=1" + "\n"; 
		macro +=  "TAG POS=1 TYPE=SPAN ATTR=TXT:siguiente" + "\n"; 
		iimPlay(macro)
		a++;
	}
}
Regads
skippyto
Posts: 108
Joined: Wed Aug 20, 2008 8:14 am

Re: Help to loop for specific times and not infinite

Post by skippyto » Thu May 15, 2014 10:39 am

Hi frankhack1,

If you want to use totalPage as number and not as a string :

Code: Select all

var totalPage = parseInt(del2) ;
Skippyto.
Post Reply