views:

7155

answers:

5

Is it possible to the raw HTML content of a web page that has been loaded into a UIWebView?

If not, is there another way to pull raw HTML content from a web page in the iPhone SDK (such as an equivalent of the .NET WebClient::openRead)?

Thanks in advance!

+15  A: 
Tim
Awesome! Thanks for the great answer. I presume both methods result in the page being loaded twice, which may have a performance impact. Is there a way to avoid that?
Fuzzy Purple Monkey
As a matter of fact, there are :) Edited answer.
Tim
Excellent, thanks :)
Fuzzy Purple Monkey
Yes, [yourWebView loadHTMLString:page baseURL:requestURL]; will run the Javascript in the page. I've used this api with Google maps.
jeff7091
A: 

this is firefox based browser?

adwords
UIWebView is based largely on WebKit, the technology that drives Safari. WebKit itself is derived from KHTML and KJS from KDE. See http://en.wikipedia.org/wiki/Safari_(web_browser)
Tim
+4  A: 

if you want to extract the contents of an already-loaded UIWebView, -stringByEvaluatingJavaScriptFromString. For example:

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

Ben Gottlieb
A: 

Is there a method to parse html content and put only the interesting parts in a uiwebview?

+2  A: 

To read:-

NSString *html = [myWebView stringByEvaluatingJavaScriptFromString: @"document.getElementById('your div id').textContent"];
NSLog(html);

To modify:-

html = [myWebView stringByEvaluatingJavaScriptFromString: @"document.getElementById('your div id').textContent=''"];
Agni