Using the LAST extracted value in a macro

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
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
tata668
Posts: 42
Joined: Sun Jun 14, 2009 2:34 am

Using the LAST extracted value in a macro

Post by tata668 » Sun Sep 27, 2009 3:50 pm

I see someone posted a similar question back in 2006, so I guess there is a solution now, but I don't find it!

I want to use the last extracted value in my macro, but {{!EXTRACT}} contains all the extracted value! Is there a way to do something like:

Code: Select all

TAG POS=1 TYPE=BODY ATTR=TXT:*hello* EXTRACT=TXT  
SET !VAR1 {{!LAST_EXTRACT}}

Thank you in advance
tata668
Posts: 42
Joined: Sun Jun 14, 2009 2:34 am

Re: Using the LAST extracted value in a macro

Post by tata668 » Sun Sep 27, 2009 3:54 pm

I think I found the answer:

- backup the current {{!EXTRACT}} to var1
- set {{!EXTRACT}} to null
- extract the value I need and set it to var2
- set {{!EXTRACT}} to null
- add var1 to {!EXTRACT}}
- add var2 to {!EXTRACT}}
Hannes, Tech Support

Re: Using the LAST extracted value in a macro

Post by Hannes, Tech Support » Mon Sep 28, 2009 7:31 am

Exactly.
Using one of the internal variables and re-setting the !EXTRACT variable does the trick.
tata668
Posts: 42
Joined: Sun Jun 14, 2009 2:34 am

Re: Using the LAST extracted value in a macro

Post by tata668 » Mon Sep 28, 2009 1:11 pm

{{!LAST_EXTRACT}} would be a good idea though...

More suggestions for a future version:

- more (unlimited?) custom variables settable inside the macro itself, not just VAR1, VAR2, VAR3
- simple "if" inside the macro itself (I know you can do this in a script):
if {{!LAST_EXTRACT}} != "#EANF#"

' do a job

endif
- We should be able to set a key for each value inside !EXTRACT. This way it would be easier in a script to know which extract is which. Currently, my workaround is to do two extracts for every value I want to extract: I first add a custom value to !EXTRACT: a unique identifier. Then I extract the value itself... In my PHP script, I know that the extract next to my unique identifier extract will be the value I'm looking for. An associated key would be way cleaner!

- A way to set our own custom error code when exiting a macro maybe?
if {{!LAST_EXTRACT}} != "#EANF#"

' the value is found, exit!
ERROR 10003

endif
Hannes, Tech Support

Re: Using the LAST extracted value in a macro

Post by Hannes, Tech Support » Tue Sep 29, 2009 8:00 am

Thanks for your suggestions! I will pass them on to the developers.

However, the short answer to most of your requests is: we don't want to create another scripting language. Instead, we'd like to make iMacros as good as possible in what it is designed for: automating/extracting web sites. Leaving everything else to the scripting/programming language of your choice.

But here's more detail:
tata668 wrote:{{!LAST_EXTRACT}} would be a good idea though...
Using iimGetLastExtract() you can address the separate extractions, cf. http://wiki.imacros.net/iimGetLastExtract
- more (unlimited?) custom variables settable inside the macro itself, not just VAR1, VAR2, VAR3
We recommend leaving the variable handling to the script. That way you can use as much as you like, with whatever name you want, and with all the methods working on it that your scripting language provides.
- simple "if" inside the macro itself (I know you can do this in a script):
And this is exactly where it should be placed. Just as all the kinds of loops (for/while/until/...).
- We should be able to set a key for each value inside !EXTRACT. This way it would be easier in a script to know which extract is which.
As said above, iimGetLastExtract() allows for accessing each of the extracted items independently. Save it to a variable and you have a unique, speaking name for it.
- A way to set our own custom error code when exiting a macro maybe?
There's a difference between macro errors (TAG not found, Syntax error, User exit) and handling the extractions. The latter surely belongs to the scripting part.
tata668
Posts: 42
Joined: Sun Jun 14, 2009 2:34 am

Re: Using the LAST extracted value in a macro

Post by tata668 » Tue Sep 29, 2009 11:37 am

Thanks for the reply Hannes!

I understand you promote the use of a script when some features are not available inside the macro itself (and I do use scripts). But as a developer, trying to use iMacros heavily, I'm telling you what I think could be improved.

The problem with always relying on a script to do the real manipulation of the data (if/else/loop/etc.) is that you have to break, you have to split your macro for every part of it requiring more control! It would be really easier to write one macro only if it would allow some very basic controle structures.

But at least I always found a way to workaround the problems I encounter when I use iMacros, so I can live with those "limitations"!

Thanks for the support!
Post Reply