views:

72

answers:

2

I'm looking to enable users to import data from websites, without giving away too much of my app, say for example to store StackOverflow questions. (It isn't really StackOverflow questions, but you get the idea, stuff that isn't being sent from a server that is kindly delivering the data in a format intended for my app).

What I'm asking in the most basic sense is can I access the stuff in the current page the user is visiting in a UIWebView (in my app, on a button press), and scan through for keywords and extract text?

Before people start asking, the purpose of this is to get rid of a barrier to switching, by allowing users to get their own content for my app from the internet, since I can't possibly supply enough of it myself.

If this is impossible, could there be a route where my app requests the page from the server directly, not via a UIWebview, (After the user has found the page in a UIWebview) and gets a copy of the source code to deal with?

Thanks for any help!

+5  A: 

Try this:

NSString *html = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];

NSString *selected = [webView stringByEvaluatingJavaScriptFromString:@"document.getSelection()"];

Also, I suggest that you check out this answer, which describes in detail other ways you can retrieve the html of a particular webpage.

Jacob Relkin
+3  A: 

And here's how to get the current selection:

NSString *selection = [webView stringByEvaluatingJavaScriptFromString:@"document.getSelection()"];
Robot K