美文网首页UI进价iOS
iOS获取H5页面图片

iOS获取H5页面图片

作者: 飘金 | 来源:发表于2017-01-10 15:36 被阅读0次

    - (void)initImg:(UIWebView*)webView{

    NSString*html = [[NSStringalloc]initWithContentsOfURL:webView.request.URLencoding:NSUTF8StringEncodingerror:nil];

    NSRegularExpression*regex = [NSRegularExpressionregularExpressionWithPattern:@"<img[^>]* src[^>]*/>"options:NSRegularExpressionAllowCommentsAndWhitespaceerror:nil];

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

    for(NSTextCheckingResult*iteminresult) {

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

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

    NSRangerangeSrc = [imgHtmlrangeOfString:@"src="];

    NSRangerangeJpg = [imgHtmlrangeOfString:@".jpg"];

    if((rangeJpg.location- rangeSrc.location-@"src=".length+@".jpg".length-1) <= imgHtml.length){

    NSString*str = [imgHtmlsubstringWithRange:(NSMakeRange(rangeSrc.location+@"src=".length+1, rangeJpg.location- rangeSrc.location-@"src=".length+@".jpg".length-1))];

    NSLog(@"正确解析出来的SRC为:%@", str);

    }

    }

    }

    }

    相关文章

      网友评论

        本文标题:iOS获取H5页面图片

        本文链接:https://www.haomeiwen.com/subject/sdgkbttx.html