How to find out number of url in the page?

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
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
pinga123
Posts: 20
Joined: Thu May 19, 2016 7:43 am

How to find out number of url in the page?

Post by pinga123 » Fri Jan 24, 2020 9:43 pm

I m using below configuration to run imacro.
firefox version : 47.0.2
Using windows 10
Imacros version : BUILD=8970419

I m trying to extract all links in the page however I m not sure how many links are there in the page .
Is there any way I can stop the execution when no link is found ( or when tag timeout ) ?

Here is the code ( Here i m assuming there are 100 links in the page However if it's less than that I need to wait till all 100 counters are completed. )

Code: Select all

for (i=1 ;i <=100 ;i++) 
	{
	

iimSet("i",i);
macro =  "CODE:";
macro +=  "VERSION BUILD=8920312 RECORDER=FX" + "\n"; 
macro +=  "SET !EXTRACT NULL" + "\n"; 
macro +=  "SET !ERRORIGNORE YES" + "\n"; 
macro +=  "SET !ERRORCONTINUE YES" + "\n"; 
macro +=  "SET !TIMEOUT_STEP 5" + "\n"; 
macro +=  "SET !TIMEOUT_TAG 5" + "\n"; 
macro += "TAG POS={{i}} TYPE=A ATTR=HREF:* EXTRACT=TXT"+ "\n"; 
retcode=iimPlay(macro);
}
User avatar
thecoder2012
Posts: 427
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: How to find out number of url in the page?

Post by thecoder2012 » Sat Jan 25, 2020 2:03 am

pinga123 wrote:
Fri Jan 24, 2020 9:43 pm
Is there any way I can stop the execution when no link is found ( or when tag timeout ) ?
Yes.
pinga123 wrote:
Fri Jan 24, 2020 9:43 pm
Here is the code ( Here i m assuming there are 100 links in the page However if it's less than that I need to wait till all 100 counters are completed. )
Is this really your code? :?:
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
chivracq
Posts: 9715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to find out number of url in the page?

Post by chivracq » Sat Jan 25, 2020 6:41 am

pinga123 wrote:
Fri Jan 24, 2020 9:43 pm
I m using below configuration to run imacro.

Code: Select all

firefox version : 47.0.2
Using windows 10
Imacros version : BUILD=8970419
I m trying to extract all links in the page however I m not sure how many links are there in the page .
Is there any way I can stop the execution when no link is found ( or when tag timeout ) ?

Here is the code ( Here i m assuming there are 100 links in the page However if it's less than that I need to wait till all 100 counters are completed. )

Code: Select all

for (i=1 ;i <=100 ;i++) 
	{
	

iimSet("i",i);
macro =  "CODE:";
macro +=  "VERSION BUILD=8920312 RECORDER=FX" + "\n"; 
macro +=  "SET !EXTRACT NULL" + "\n"; 
macro +=  "SET !ERRORIGNORE YES" + "\n"; 
macro +=  "SET !ERRORCONTINUE YES" + "\n"; 
macro +=  "SET !TIMEOUT_STEP 5" + "\n"; 
macro +=  "SET !TIMEOUT_TAG 5" + "\n"; 
macro += "TAG POS={{i}} TYPE=A ATTR=HREF:* EXTRACT=TXT"+ "\n"; 
retcode=iimPlay(macro);
}

>>>
thecoder2012 wrote:
Sat Jan 25, 2020 2:03 am
pinga123 wrote:
Fri Jan 24, 2020 9:43 pm
Here is the code ( Here i m assuming there are 100 links in the page However if it's less than that I need to wait till all 100 counters are completed. )
Is this really your code? :?:

Ah-ah-ah...!, LOL...! You got me a huge big Smile on my Face, @thecoder, ah-ah...! :wink: :P

Yep, same "Feeling", I was "waiting" for @OP to finish their previous Thread a bit "correctly" to improve the Readability, but I was also going to "say stg", ah-ah...! :P

The '!ERRORIGNORE' comes "from me" I think, as I mentioned in their previous Thread that '!ERRORCONTINUE' had been deprecated for 8 or 10 years, so they added '!ERRORIGNORE' without removing the old '!ERRORCONTINUE', oops...!
And the '!TIMEOUT_TAG' is "new" from this Thread, it was not included in their Script in the previous Thread, no Idea where they got it from...! :shock:
=> @OP, that Command is also deprecated since 8-10 years, and got replaced by ''!TIMEOUT_STEP', but you don't need both...
But Users using those Commands should now be able to answer 90% of all Threads on the Forum by now, if they've been using iMacros for so long...! :idea:
(And the "SET !EXTRACT NULL" also has no real Use in the Script posted...)

>>>

Hum, and @thecoder, I mentioned you at some point in their previous Thread, which is about Social Media ('Instagram'), so I didn't want to help @OP "too precisely", but there was some part in that Thread when I say "I "see"..." etc that you might find "Interesting"... :wink:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
frankhack1
Posts: 83
Joined: Fri Mar 20, 2009 9:12 pm

Re: How to find out number of url in the page?

Post by frankhack1 » Wed Mar 18, 2020 9:46 pm

This should work

Code: Select all

function macroFunc() {
		
var macro;
     macro =  "CODE:";
	
// PARAMETERS
macro +=  "SET !ERRORIGNORE YES" + "\n";
macro +=  "SET !TIMEOUT_TAG 5" + "\n"; 

// EXTRACT AND EVALUATE
macro += "TAG POS={{loop}} TYPE=A ATTR=HREF:* EXTRACT=TXT"+ "\n";

 // INFINITE LOOP
var start = 1;
for (i=start;;i++) {
iimSet("loop",i)

iimPlay(macro)

// BREAK WHEN THERE IS NO MORE LINKS
var text=iimGetLastExtract();
if(text.search("EANF")!=-1)
{
break;
}
}
}

// CALL FUNC
macroFunc()
access2vivek
Posts: 69
Joined: Wed Dec 20, 2017 10:00 am
Location: New Delhi, India
Contact:

Re: How to find out number of url in the page?

Post by access2vivek » Sun Jun 14, 2020 7:46 am

pinga123 wrote:
Fri Jan 24, 2020 9:43 pm

I m trying to extract all links in the page however I m not sure how many links are there in the page .
Is there any way I can stop the execution when no link is found ( or when tag timeout ) ?

Here is the code ( Here i m assuming there are 100 links in the page However if it's less than that I need to wait till all 100 counters are completed. )

Code: Select all

for (i=1 ;i <=100 ;i++) 
	{
	

iimSet("i",i);
macro =  "CODE:";
macro +=  "VERSION BUILD=8920312 RECORDER=FX" + "\n"; 
macro +=  "SET !EXTRACT NULL" + "\n"; 
macro +=  "SET !ERRORIGNORE YES" + "\n"; 
macro +=  "SET !ERRORCONTINUE YES" + "\n"; 
macro +=  "SET !TIMEOUT_STEP 5" + "\n"; 
macro +=  "SET !TIMEOUT_TAG 5" + "\n"; 
macro += "TAG POS={{i}} TYPE=A ATTR=HREF:* EXTRACT=TXT"+ "\n"; 
retcode=iimPlay(macro);
}
This can easily be achieved by: -

Code: Select all

for(var loop=1;;loop++)
{
    iimPlayCode("SET !TIMEOUT_STEP 3\nTAG POS="+loop+" TYPE=A ATTR=HREF:* EXTRACT=TXT");
    if(iimGetLastExtract()=="#EANF#")
        break;
     // To save the link text somewhere, you can use something like:-
     // links.push(iimGetLastExtract());
}
The above code will wait 3 seconds for the last link to be loaded. If it doesn't load within 3 seconds of the last extracted link, the loop will terminate.
I hope it helps :-)
Robust iMacros development with quick turnaround time. Drop an email at "access2content@gmail.com" with your project details.
Post Reply