1

I am new to iphone, i am trying to parse a webpage. In that webpage we table of contents

headed with Country, code , location, population. And if we click on any country name then it

navigates to another page. My intension is to get the county name and country code from this

webpage and use in my app. Please help me in doing so. thank you

Raju goud Bingi
  • 160
  • 2
  • 13

2 Answers2

4

You can make a request to the page using any 3rd party libraries for that purpose (MKNetworkKit, for example) or just the basic NSURLConnection. After that, you will receive the HTML on the response which can be parsed and used for whatever you want.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
2

If you are using a UIWebView, you can execute any custom javascript code on your web page from your app code. So, if you're familiar with javascript, DOM and HTML (and maybe CSS) that would not be a problem for you.

For example, say you have a div (or whatever, tr, td or anything with HTML contents) in your web page with id = "country" and you want to make textual contents(HTML) of that div available in your code:

...html...

<div id="country">
    Inner html of country div
</div>

...html...

Then in your app code, after your web page had finished loading into a web view, call:

NSString* innerHTML =  [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"country\").innerHTML"];

That's it, your have data from desired div. You can use this approach to gain any data from a web page in web view, varying executed javascript code.

MANIAK_dobrii
  • 6,014
  • 3
  • 28
  • 55
  • no, i need parse the data from a webpage for which i have the url – Raju goud Bingi Jul 02 '12 at 10:09
  • Then Jacky Boy's approach is the one you need. You receive web page's html and parse it. You may find some info about html parsing [here](http://stackoverflow.com/questions/4942032/html-file-parsing-in-iphone-sdk) and [here](http://stackoverflow.com/questions/8951923/parsing-html-url-in-iphone) – MANIAK_dobrii Jul 02 '12 at 11:04