Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa: get WebView mainFrame html string

I'm creating an Mac app that loads some content from a URL in a WebView and then needs to save the content to a file. The content may and may not be HTML. Loading works fine, the problem is to get the content from the WebView. How do I do that?

Thanks!

like image 812
Fernando Valente Avatar asked Feb 12 '12 07:02

Fernando Valente


1 Answers

I do not know if you use WebView (MacOS) or UIWebVoew (iOS...). I use the following code (in MacOS) which works well for me:

WebFrame *frame = [myWebView mainFrame];
WebDataSource *source = [frame dataSource];
NSData *data = [source data];
NSString *str = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
[someTextView setString:str];  // shows the content of myWebView as string
like image 192
Heinrich Giesen Avatar answered Nov 17 '22 22:11

Heinrich Giesen