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];
}
}];
获取html中所有img
时间: 2024-10-01 04:48:16