应用程序崩溃时解析HTML链接&哪个解析器是最好的hpple或Objective-C-HTML-Parser?

时间:2012-01-04 18:34:01

标签: iphone ipad

我正在使用 hpple 以这种方式从html链接解析数据(正文内容):

TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData]; 
NSArray *elements  = [xpathParser search:@"body"];

它崩溃了,所以我将搜索标记更改为@"<body>"

TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements  = [xpathParser search:@"<body>"];

应用程序再次崩溃。如何获取body标签中提供的信息? 哪个解析器最好是hpple还是Objective-C-HMTL-Parser?

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

htmlParser = [[TFHpple alloc] initWithHTMLData:[[responseString stringByDecodingHTMLEntities] dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];
elements  = [htmlParser searchWithXPathQuery:@"//body"];

你忘了“//”,表示在任何深度搜索。请注意,在此示例中,我使用了MWFeedParser的一种很棒的方法; stringByDecodingHTMLEntities,它帮助我在XML文档中进行HTML解析

相关问题