获取UIWbview中的所有图片

NSString *yourHTMLSourceCodeString = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];

    NSError *error = NULL;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(<img src=\"(.*?)\">)+?"
                                                                           options:NSRegularExpressionCaseInsensitive
                                                                             error:&error];

    NSArray *matches = [regex matchesInString:yourHTMLSourceCodeString
                                      options:0
                                        range:NSMakeRange(0, [yourHTMLSourceCodeString length])];

    NSLog(@"total matches %d",[matches count]);

    for (NSTextCheckingResult *match in matches) {
        NSString *img = [yourHTMLSourceCodeString substringWithRange:[match rangeAtIndex:2]] ;
        NSLog(@"img src %@",img);
    }
posted @ 2014-08-05 13:42  zengyanzhi  阅读(111)  评论(0编辑  收藏  举报