标签:
解析非utf-8页面的思路 :
具体代码如下:
1 // 1. 获取Data 2 NSURL *postDetailUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", BASEURL, self.topicUrl]]; 3 NSData *postDetailHtmlData = [NSData dataWithContentsOfURL:postDetailUrl]; 4 5 // 2. 转码成utf8Data:先转成gb2312, 替换meta, 然后转成utf8 6 NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); 7 NSString *postHtmlStr = [[NSString alloc] initWithData:postDetailHtmlData encoding:gbkEncoding]; 8 9 NSString *uft8HtmlStr = [postHtmlStr stringByReplacingOccurrencesOfString:@"<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=gb2312\">" withString:@"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"]; 10 NSData *utf8HtmlData = [uft8HtmlStr dataUsingEncoding:NSUTF8StringEncoding];
http://blog.csdn.net/toolazytoname/article/details/10051681
iOS开发-- TFHpple抓取GB-2312编码的html页面,页面返回编码错误
标签:
原文地址:http://www.cnblogs.com/feiling/p/4808900.html