I have an interesting scenario and need to know if it can even be done in Cocoa.
I have tried and failed to find a hourly weather forecast api that is free and will let me see hour-by-hour forecast for a certain city/zipcode. So for an alternate approach what I am trying to do is to read the whole HTML page source and try to see if I can strip out the hourly weather portion so that I can use it in my iPhone app.
NSString *request = @"http://www.findlocalweather.com/hourly/il/chicago.html";
NSURL *URL = [NSURL URLWithString:request];
NSError *error;
NSString *HTML = [NSString stringWithContentsOfURL:URL encoding:NSASCIIStringEncoding error:&error];
NSLog(@"HTML: %@", HTML);
If you go to the http://www.findlocalweather.com/hourly/il/chicago.html link you will see the grid hourly forecast. What I need to do is from that HTML source I need to read each date, clouds and temp lines and put that into arrays. e.g.
NSMutableArray1 will contain objects “AUG 05 9:00 AM, AUG 05 10:00 AM, AUG 05 11:00 AM …”
NSMutableArray2 will contain objects “Mostly Cloudy, Mostly Sunny …”
NSMutableArray3 will contain objects “73, 84, 76, 91 ….” (temp in degrees)
Can this be done? Anyone ever tried parsing a HTML page source string to get what you want out of it?
You could do it easily with NSRegularExpression
There are some nice tutorials how to use Regular Expressions (They are almost the same in most programming languages, but look after the specialties of NSRegEx)
Example: Parsing pdf links out of HMTL file.
I wrote this code a while ago. I would advise you experiment a bit and make use of NSLog or Breakpoints. This will help a lot. It takes some time to get into the RegEx Stuff but it works very good.