Iterating through variables
Is there some way to iterate through the variables in a scrape? I'm trying to write a script that populates a meta-dataset including information like passed values, number of records returned, timing, etc.
I'd prefer to iterate through the session variables rather than hardcode an entry for each possible passed parameter. Generic is better than specific, right? :)
Iterating through variables
Hi,
There are two ways you could go about this. They both involve unpublished API method calls, though, so I'll give the caveat that you should use these at your own risk.
The first would be to use a feature we experimented with for a while that would allow you to save all session variables to a file so that they could be loaded back in at a later point. The method call looks like this:
session.saveState( [path_to_file] );
Where [path_to_file] is the path to a file to which you'd like the values written.
The second approach would be to access the scraping session's state object directly, and get the variables from it. It would look something like this:
java.util.Hashtable = session.getScrapingSessionState().getVariables();
You could then iterate over the keys and values as you normally would with a Hashtable (http://java.sun.com/j2se/1.4.2/docs/api/java/util/Hashtable.html).
Hopefully one of those does the trick for you. Feel free to post back if we can help further.
Kind regards,
Todd Wilson