Input from array
The following script is really useful when you need to loop through a short series of input parameters. Using an array will allow you to rapidly develop a group of inputs that you would like to use; however, you will need to know every input parameter. For example, if you wanted to use the following state abbreviations as inputs [UT, NY, AZ, MO] then building an array would be really quick, but if you needed all 50 states it would probably be easier to access those from a csv (need to know how to use a csv input? check out my other post titled "Moderate Initialize -- Input from CSV").
import java.io.*;
String[] states = {"DE", "FL", "GA", "MD", "NH", "NC", "PA", "RI", "SC", "TN", "VT", "VA", "MS"};
int i = 0;
while ( i<states.length )
{
if (!session.shouldStopScraping())
{
session.setVariable("STATE", states[i]);
session.log("***Beginning STATE: " + session.getVariable("STATE"));
session.scrapeFile("Search Results");
i++;
}
}
String[] states = {"DE", "FL", "GA", "MD", "NH", "NC", "PA", "RI", "SC", "TN", "VT", "VA", "MS"};
int i = 0;
while ( i<states.length )
{
if (!session.shouldStopScraping())
{
session.setVariable("STATE", states[i]);
session.log("***Beginning STATE: " + session.getVariable("STATE"));
session.scrapeFile("Search Results");
i++;
}
}
scraper on 07/16/2010 at 4:24 pm
- Printer-friendly version
- Login or register to post comments