sample code wanted, go to a page, read content on a 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
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

sample code wanted, go to a page, read content on a page

Post by questions » Fri Jan 16, 2009 10:55 pm

can anyone post some sample code in js or vb that will go to a page, read some text on a page, perform an if then on the text then do one thing if the text says A or do another thing if the text says B or do another thing if the text says C?

would be nice to see the same code in js and vb... thanks!
User avatar
Tech Support
Posts: 4947
Joined: Tue Sep 20, 2005 7:25 pm
Contact:

Re: sample code wanted, go to a page, read content on a page

Post by Tech Support » Wed Jan 21, 2009 4:16 pm

You need some basic if/then decisions. Please see any of the examples on this page: http://wiki.imacros.net/Sample_Code
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

Re: sample code wanted, go to a page, read content on a page

Post by questions » Thu Jan 29, 2009 3:28 am

but how do you read some text on a page into a variable?

for example, what is the js code to use imacros to read this page and if it contains the word findthis then it runs macro1.iim?
josephconlin
Posts: 190
Joined: Wed Aug 06, 2008 2:38 am

Re: sample code wanted, go to a page, read content on a page

Post by josephconlin » Thu Jan 29, 2009 11:55 pm

questions wrote:but how do you read some text on a page into a variable?

for example, what is the js code to use imacros to read this page and if it contains the word findthis then it runs macro1.iim?
You have the macro do an extract of the data you are looking for, then you use iimGetLastExtract() to get that data into a variable. Here's an incomplete example from one of my scripts.

Code: Select all

var itemNumber = 1;
var macro="CODE:";
macro+="TAB T=1\n";
macro+="TAG POS="+itemNumber+" TYPE=B ATTR=TXT:View EXTRACT=TXT\n";

retcode = iimPlay(macro);

if (retcode < 0)               // an error has occured
{
	errtext = iimGetLastError();
	alert(errtext);
}

var flag = iimGetLastExtract();
...

//Loop until all items are processed
while(flag != "#EANF#")
{
...
}
In the first section, I set up a macro to look for TAG POS="+itemNumber+" TYPE=B ATTR=TXT:View EXTRACT=TXT. I start with itemNumber set to 1, and I will increase it later in the while loop (not shown, it's in the ... part *grin*).

In the next section, I run the macro and check for any problems with it running. After that, I create a variable called flag and set it to iimGetLastExtract().

Finally, in the while loop, I first check the flag variable to see if it's equal to #EANF#. If it is, the TAG command I ran before found nothing, and the script goes on to the section after the loop. You could just as easily do something with if(flag == "findthis") or anything you like. If flag is something other than #EANF#, the script goes into the loop where it does what I need, increases the itemNumber variable by 1, runs the macro to check for the data, and then sets flag to iimGetLastExtract() again. Then the loop checks the value of flag again, and the whole loop starts again or is exited.
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

Re: sample code wanted, go to a page, read content on a page

Post by questions » Sat Jul 25, 2009 6:08 pm

can you post an entire example (complete script) of how to look for a bit of text and if it finds it it runs a javascript macro and if it doesn't find it it says "ROBOT CAN'T FIND TEXT"

then the same code on how to look for a certain image, but the image has a wildcard in the filename (img*9999.gif) if it finds it it runs a javascript macro and if it doesnt find it it says "ROBOT CAN'T FIND IMAGE"
josephconlin
Posts: 190
Joined: Wed Aug 06, 2008 2:38 am

Re: sample code wanted, go to a page, read content on a page

Post by josephconlin » Wed Jul 29, 2009 5:39 pm

questions wrote:can you post an entire example (complete script) of how to look for a bit of text and if it finds it it runs a javascript macro and if it doesn't find it it says "ROBOT CAN'T FIND TEXT"

then the same code on how to look for a certain image, but the image has a wildcard in the filename (img*9999.gif) if it finds it it runs a javascript macro and if it doesnt find it it says "ROBOT CAN'T FIND IMAGE"
I don't normally write macros for others, but I did in another post. Maybe this post will help. http://forum.imacros.net/viewtopic.php?f=11&t=7537
Post Reply