我正在使用MWFeedParser在我的应用程序中下载提要。到目前为止,它运行良好-然而,我无法解析每一篇文章为它的图像URL。这是我目前的代码:
// MWFeedItem.h
NSData* firstImg;
@property (nonatomic, retain) NSData* firstImg;
MWFeedItem.m
add synthesize and dealoc// RootViewController.m
- (NSString *)getFirstImage:(NSString *)htmlString{
NSScanner *theScanner;
NSString *text = nil;
theScanner = [NSScanner scannerWithString: htmlString];
// find start of tag
[theScanner scanUpToString: @"<img src=\"" intoString: NULL];
if ([theScanner isAtEnd] == NO) {
NSInteger newLoc = [theScanner scanLocation] + 10;
[theScanner setScanLocation: newLoc];
// find end of tag
[theScanner scanUpToString: @"\"" intoString: &text];
}
return text;
}
(void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
NSLog(@"Parsed Feed Item: “%@”", item.title);
NSString* str_imageUrl = [self getFirstImage:item.summary];
item.firstImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:str_imageUrl]];
if (item) [parsedItems addObject:item];
}我不能用这段代码查看图像,我也不知道为什么。
发布于 2013-06-28 15:04:47
试试CXFeedParser。它是从MWFeedParser分叉的,并包含一个NSArray图像为每个feedItem。
https://stackoverflow.com/questions/17248841
复制相似问题