How to add http parameters to a scrape file
Hi,
How do I add parameters to a scrapeFile that is only about to be invoked? The scrapeableFile.addHTTPParameter() function only adds parameters to the currently executing scrapeFile. What I want to do is setup all the parameters prior to doing a session.scrapeFile().
Is the only way to do it -- save it to some session variable; call the scrapefile; at the "execute before file is scraped" script, retrieve session variables and load via addHTTPParameter()? Is there a simpler way of doing it prior to actually calling the scrapeFile?
Dick
You're right that you have to
You're right that you have to save the parameters as a variable, and then use a script to create the POST parameters on the scrapeable file on which you want to use them.
Here's a template script I use to do this:
// Script to dynamically create POST parameters for next page
// Function to actually create the parameter
makeParam(name, value, index)
{
scrapeableFile.addHTTPParameter(new com.screenscraper.common.HTTPParameter(name,value,index,com.screenscraper.common.HTTPParameter.TYPE_POST));
}
// Dataset that contains each paramter as a dataRecord
params = session.getVariable("Next page parameters");
// Clear so large values don't linger in memory
session.setVariable("Next page parameters", null);
session.log("+++There are " + params.getNumDataRecords() + " parameters");
// Loop through each paramter
{
for (i=0; i
param = params.getDataRecord(i);
key = param.get("NAME");
// The the key is "eventtarget", I need to set the value from a seperate location
if (key.equals("__EVENTTARGET"))
value = session.getVariable("PAGE");
else
value = param.get("VALUE")!=null ? param.get("VALUE") : "";
session.log("Making param: " + key + "=" + value);
makeParam(key, value, i+1);
}