Relative Positioning in iMacros 7

Information related to the use of iMacros for Web Scraping, Data Mining and creating Mashups.

Moderator: iMacros Moderators

Relative Positioning in iMacros 7

by Tom, Tech Support on Mon Jul 19, 2010 5:34 am

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
Tom, Tech Support
 
Posts: 3297
Joined: Mon May 31, 2010 9:59 am

Return to How-To's and Examples for Web Scraping

Who is online

Users browsing this forum: No registered users and 1 guest

-->