Objective-C-HMTL-Parser解析乱码问题的解决

Objective-C-HMTL-Parser是Objective-c实现的一个Html杰解析库,地址为:https://github.com/zootreeves/Objective-C-HMTL-Parser
在使用Objective-C-HMTL-Parser解析中文网页的时候经常出现中文乱码的问题,主要问题是页面没有指定编码格式,通过下面代码指定编码格式即可解决乱码的问题:

NSString * fileContent = [NSString stringWithContentsOfURL:[NSURL URLWithString:allUrl] encoding:(NSUTF8StringEncoding) error:&error];
fileContent = [fileContent stringByReplacingOccurrencesOfString:@"/><link" withString:@" charset=utf-8/><link"];
HTMLParser *parser = [[HTMLParser alloc] initWithString:fileContent error:&error];

 

This entry was posted in iOS.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">