获取html中所有img

NSError *error = NULL;

    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(<img\\s[\\s\\S]*?src\\s*?=\\s*?['\"](.*?)['\"][\\s\\S]*?>)+?"

                                                                           options:NSRegularExpressionCaseInsensitive

                                                                             error:&error];

    

    [regex enumerateMatchesInString:_article.htmlContent

                            options:0

                              range:NSMakeRange(0, [_article.htmlContent length])

                         usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {

                             

                             NSString *img = [_article.htmlContent substringWithRange:[result rangeAtIndex:2]];

                             NSLog(@"img src %@",img);

                             if ([img rangeOfString:@"share_btn"].location == NSNotFound) {

                                 [_imagesArray addObject:img];

                             }

                         }];

posted @ 2014-08-19 09:42  zengyanzhi  阅读(619)  评论(0编辑  收藏  举报