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



我使用 apple 以这种方式从html链接解析数据(主体内容):

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

崩溃了,所以我把搜索标签改成了@"<body>"

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

应用程序再次崩溃。我怎样才能得到正文标签&

尝试如下:

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

您忘记了"//",这表示在任何深度搜索。注意,在这个例子中,我使用了一个很好的方法MWFeedParser;stringByDecodingHTMLEntities,它帮助我在XML文档中解析HTML

最新更新