Initialize--Iterating through multiple input files

Many sites requiring the user to input a zip code when performing a search. For example, when searching for car listings, a site will ask for the zip code where you would like to find a car (and perhaps distance from the entered zip code that would be acceptable). The follow script is designed to iterate through a set of input files, which each contain a list of zip codes for that state. The input files in this case are located within a folder named "input" in the screen-scraper directory. The files are named in the format "zips_CA", for example, which would contain California's zip codes.

 import java.io.*;<br />
<br />
String[] states =  {"AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI",<br />
"ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE",<br />
"NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","PR","RI","SC","SD","TN",<br />
"TX","UT","VT","VA","WA","WV","WI","WY"};<br />
<br />
i = 0;<br />
<br />
// Iterate through each state abbreviation in the array above<br />
while (i < states.length){<br />
    ////////////////////////////////////////////<br />
    // The file changes depending on what state we are scraping<br />
    session.setVariable("INPUT_FILE", "input/zips_"+ states[i] + ".csv");<br />
    ////////////////////////////////////////////<br />
<br />
    BufferedReader buffer = new BufferedReader(new FileReader(session.getVariable("INPUT_FILE")));<br />
    String line = "";<br />
<br />
    while ((line = buffer.readLine()) != null){<br />
        // The input file in this case will have one zip code per line<br />
        session.setVariable("ZIPCODE", line);<br />
<br />
        session.log("***Beginning zip code " + session.getVariable("ZIPCODE"));<br />
<br />
         // Scrape the "Search Results" with the new zip code retrieved from the<br />
         // current state's file<br />
        session.scrapeFile("Search Results");<br />
    }<br />
i++;<br />
}
Attachment Size
zips_AL.csv 5.73 KB
zips_AR.csv 4.16 KB
zips_AZ.csv 3.03 KB
zips_CA.csv 20.7 KB
zips_CO.csv 4.53 KB