ios 提取html网页字符串中的img(图片地址) 的地址

```

+ (NSArray*)filterImage:(NSString*)html{

    NSMutableArray *resultArray = [NSMutableArray array];

    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<(img|IMG)(.*?)(/>|>|>)" options:NSRegularExpressionAllowCommentsAndWhitespace error:nil];


    NSArray*result = [regexmatchesInString:htmloptions:NSMatchingReportCompletionrange:NSMakeRange(0, html.length)];


    for(NSTextCheckingResult*iteminresult) {


        NSString*imgHtml = [htmlsubstringWithRange:[itemrangeAtIndex:0]];

        NSArray*tmpArray =nil;


        if([imgHtmlrangeOfString:@"src=\""].location!=NSNotFound) {

            tmpArray = [imgHtmlcomponentsSeparatedByString:@"src=\""];

        }elseif([imgHtmlrangeOfString:@"src="].location!=NSNotFound) {

            tmpArray = [imgHtmlcomponentsSeparatedByString:@"src="];

        }


        if(tmpArray.count>=2) {


            NSString*src = tmpArray[1];

            NSUIntegerloc = [srcrangeOfString:@"\""].location;

            if(loc !=NSNotFound) {

                src = [srcsubstringToIndex:loc];

                [resultArrayaddObject:src];


            }


        }


    }


    returnresultArray;


}

```

你可能感兴趣的:(ios 提取html网页字符串中的img(图片地址) 的地址)