Relative Positioning in iMacros 7

Information related to the use of iMacros for Web Scraping, Data Mining and creating Mashups.
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
Post Reply
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Relative Positioning in iMacros 7

Post by Tom, Tech Support » Mon Jul 19, 2010 12:34 pm

In order to keep iMacros 7 compatible with iMacros for Firefox as much as possible, we had to change the iMacros relative positioning algorithm. Therefore, it is no longer possible to tag an element relative to its outer element in a nested situation.

This is easier to understand with a simple example. The following macro first tags the table cell TD and looks for the next occurrence of a link.

Code: Select all

URL GOTO=http://www.iopus.com/imacros/demo/v6/extract2/
TAG POS=1 TYPE=TD ATTR=CLASS:bdytxt&&TXT:HREF<SP>extracts<SP>links
TAG POS=R1 TYPE=A ATTR=TITLE:* EXTRACT=TXT
While v6 extracts the link which is inside that table cell, namely "HREF extracts links", v7 and iMacros for Firefox extract the next link's text: "keyword detection with EXTRACT".

Knowing that relative positioning is relative to the element's end, all you have to do is change the anchor (reference) tag. For instance, the v6 macro for extracting the values in each table row:

Code: Select all

VERSION BUILD=6851105 
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=http://www.x-rates.com/
'Anchor to the exchange rates table
TAG POS=2 TYPE=TABLE ATTR=TXT:<SP><SP><SP><SP>USD<SP><SP><SP><SP>GBP*
'Extract each of the rows *inside* the table
SET !LOOP 3
TAG POS=R{{!LOOP}} TYPE=TR ATTR=TXT:* EXTRACT=TXT
can be easily adapted to:

Code: Select all

VERSION BUILD=706710521
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=http://www.x-rates.com/
'Anchor to the header row
TAG POS=4 TYPE=TR ATTR=TXT:<SP><SP><SP><SP>USD<SP><SP><SP><SP>GBP*
'Extract each of the rows *below* the header
TAG POS=R{{!LOOP}} TYPE=TR ATTR=TXT:* EXTRACT=TXT
Notice that both produce the same result, but in the first version !LOOP has to run from 3 to 7, while the new version needs to !LOOP from 1 to 5 to get all the rows in the table.

Alternatively, you can use XPATH to position the tag. iMacros 7 also supports XPath expressions in the TAG command, although not the id() function
Regards,

Tom, iMacros Support
Post Reply