每个网站的源代码都有一个网址(.txt)吗?
如果没有,我如何获取网页的源代码并能够在UITextView中显示它?
发布于 2011-10-23 19:44:19
您应该能够使用下面这样的内容:
NSString *googleString = @"http://www.google.com";
NSURL *googleURL = [NSURL URLWithString:googleString];
NSError *error;
NSString *googlePage = [NSString stringWithContentsOfURL:googleURL
encoding:NSASCIIStringEncoding
error:&error];这会将谷歌主页的内容放入googlePage中,如果适用,还会将错误放入error中。如果要加载的页面使用Unicode字符,请尝试使用NSUTF8StringEncoding而不是NSASCIIStringEncoding。
https://stackoverflow.com/questions/7865857
复制相似问题