Just in case anyone else fancies a play around with this year's Vancouver Olympics medals/competitors etc, I've made a bit of code that gets all the medallists' names, their nationalities, medals(g/s/b), and the event they won them in. I'm not sure it's done in the slickest way, but it might save someone else a bit of time!
Code://SOURCE: http://espn.go.com/olympics/winter/2010/results/_/date/20100220
String[] sourceAddressesByDateArray = new String[17];//17 days of olympics.
int anyMoreGroups = 1;
void setup(){
size(200, 200);
for(int i=0; i<sourceAddressesByDateArray.length; i++){//loop through the days results...
sourceAddressesByDateArray[i] = "http://espn.go.com/olympics/winter/2010/results/_/date/201002"+(12+i);//gets the url of each day's results table.
println("loading day"+(i+1)+"strings");
String[] tempDaySourceLines = loadStrings(sourceAddressesByDateArray[i]);
if(tempDaySourceLines != null){// if I've got the source strings & it's ok continue..
String tempDaySource = join(tempDaySourceLines, " ");//joins all source for day.
String[] currentDayGroupsSourceArray = split(tempDaySource, "stathead");//splits the source into an array for each group( alpine/nordic etc).
println(sourceAddressesByDateArray[i]);
println("On this day there were "+(currentDayGroupsSourceArray.length-1)+" groups");
//println(currentDayGroupsSourceArray);//prints array of all the day's groups source.
for(int b=1; b<currentDayGroupsSourceArray.length; b++){//loop through groups and split into events.
String[] thisDaysEventsArray = split(currentDayGroupsSourceArray[b], "colhead");//splits the group into events.
println((thisDaysEventsArray.length-1)+" events in group "+b);// Array [0] is group title.
println(thisDaysEventsArray);//prints array of the day's events source.
//THIS IS WITHIN EACH EVENT, OF ALL DAYS.
//now within each event, get any medals awarded & get winner.
for(int n=1; n<thisDaysEventsArray.length; n++){//for every event this day..
int startGetEvent = thisDaysEventsArray[n].indexOf("\"4\">")+4;
int endGetEvent = thisDaysEventsArray[n].indexOf("<", startGetEvent);
String event = thisDaysEventsArray[n].substring(startGetEvent, endGetEvent);
println("EVENT - "+event);
if(thisDaysEventsArray[n].indexOf("medalimage-G")>=0){//if there is a GOLD medal in the current event..
int startGetGoldCountry = thisDaysEventsArray[n].indexOf(" ")+6;
int endGetGoldCountry = thisDaysEventsArray[n].indexOf(" ")+9;
String goldCountry = thisDaysEventsArray[n].substring(startGetGoldCountry, endGetGoldCountry);
println(goldCountry+" goldCountry");
int preGetAthleteName = thisDaysEventsArray[n].indexOf("href")+4;
int startGetAthleteName = thisDaysEventsArray[n].indexOf(">", preGetAthleteName)+1;
int endGetAthleteName = thisDaysEventsArray[n].indexOf("<", startGetAthleteName);
String athleteName = thisDaysEventsArray[n].substring(startGetAthleteName, endGetAthleteName);
println(athleteName);
}
if(thisDaysEventsArray[n].indexOf("medalimage-S")>=0){//if there is a SILVER medal in the current event..
int startGetSilverCountry = thisDaysEventsArray[n].indexOf("medalimage-S")+12;
int endGetSilverCountry = thisDaysEventsArray[n].indexOf(" ", startGetSilverCountry)+9;
String silverCountry = thisDaysEventsArray[n].substring(endGetSilverCountry-3, endGetSilverCountry);
println(silverCountry+" silverCountry");
int lookFromIndex = thisDaysEventsArray[n].indexOf("medalimage-S");
int preGetAthleteName = thisDaysEventsArray[n].indexOf("href", lookFromIndex)+4;
int startGetAthleteName = thisDaysEventsArray[n].indexOf(">", preGetAthleteName)+1;
int endGetAthleteName = thisDaysEventsArray[n].indexOf("<", startGetAthleteName);
String athleteName = thisDaysEventsArray[n].substring(startGetAthleteName, endGetAthleteName);
println(athleteName);
}
if(thisDaysEventsArray[n].indexOf("medalimage-B")>=0){//if there is a BRONZE medal in the current event..
int startGetBronzeCountry = thisDaysEventsArray[n].indexOf("medalimage-B")+12;
int endGetBronzeCountry = thisDaysEventsArray[n].indexOf(" ", startGetBronzeCountry)+9;
String bronzeCountry = thisDaysEventsArray[n].substring(endGetBronzeCountry-3, endGetBronzeCountry);
println(bronzeCountry+" bronzeCountry");
int lookFromIndex = thisDaysEventsArray[n].indexOf("medalimage-B");
int preGetAthleteName = thisDaysEventsArray[n].indexOf("href", lookFromIndex)+4;
int startGetAthleteName = thisDaysEventsArray[n].indexOf(">", preGetAthleteName)+1;
int endGetAthleteName = thisDaysEventsArray[n].indexOf("<", startGetAthleteName);
String athleteName = thisDaysEventsArray[n].substring(startGetAthleteName, endGetAthleteName);
println(athleteName);
}
if(thisDaysEventsArray[n].indexOf("medalimage")<0){//if there are no medals to get for the event..
println("No medals awarded for this event");
}
}//end of every event loop.
}//end of group loop.
}//end of if source != null.
println(" ");//space out the printed blocks a bit.
}//end of main loop.
}//end of setup.