UI进价iOS

iOS获取H5页面图片

2017-01-10  本文已影响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);

}

}

}

}

上一篇下一篇

猜你喜欢

热点阅读