Raju goud Bingi
Raju goud Bingi

Reputation: 160

How to parse the webpage in iphone, and how to get the part of data from table of that webpage ?

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

Upvotes: 1

Views: 463

Answers (2)

MANIAK_dobrii
MANIAK_dobrii

Reputation: 6032

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.

Upvotes: 1

Rui Peres
Rui Peres

Reputation: 25917

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.

Upvotes: 3

Related Questions