开发者

Is it possible to access the HTML code of a UIWebView, or access a selection, or both?

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 t开发者_如何转开发he page in a UIWebview) and gets a copy of the source code to deal with?

Thanks for any help!


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.


And here's how to get the current selection:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜