5

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!

Fernando Valente
  • 1,096
  • 1
  • 8
  • 30
  • This would help [How to save the content in UIWebView for faster loading on next launch?](http://stackoverflow.com/questions/1343515/how-to-save-the-content-in-uiwebview-for-faster-loading-on-next-launch) – Ahmad Kayyali Feb 12 '12 at 07:25

1 Answers1

9

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
Heinrich Giesen
  • 1,765
  • 1
  • 11
  • 8