views:

160

answers:

2

Is it possible to pull information from a website and display it in an iphone application? I am looking to pull the current temperature and barometric pressure for an airport from the http://adds.aviationweather.noaa.gov website and display those two pieces of information in an app.

This sounds like a common task that programs do all the time but I'm not sure how it's incorporated into an app.. (what is the process of pulling webdata called?)

What methods or tools are available to do this? I am unfamiliar with handling web data for iphone at this time.

A: 

Just use an NSHTTPRequest and all the related classes to assemble a standard HTTP GET request for the site with the data you need. If there's a data feed (XML, JSON, etc.), you should find out what that URL is and use it instead of parsing the actual HTML of the web page. If not, the method is called "screen scraping" and it basically involves you writing a regular expression to parse the HTML of the web page returned from the server. Again, don't do this unless there is no alternative data feed you can use.

If you need to parse XML, see NSXMLParser. There are open-source solutions for parsing JSON in Objective-C. Just Google around for them.

Marc W
thanks for the terminology - (I knew there was a term for it)
samfu_1
A: 

If they have an actual feed for the data, you could access it using NSHTTPRequest and parse the results.

If you need to screen-scrape the data off the page itself, then I would highly suggest creating your own web service to do the parsing and have your iPhone app talk to your web service. The reason being that if they update the page in a way that breaks your screen scraping you would only have to update your web service instead of deploying an update out to who-knows-how-many iPhones.

Eric Petroelje
so developing a webservice would be designing an entity that grabs the data (scrapes the screen) and then talks to the iphone app specifically. Good idea instead of having to update the app itself.
samfu_1