- (void)webViewDidFinishLoad:(UIWebView *)webView
{//这里是js,主要目的实现对url的获取
static NSString * const jsGetImages =
@"function getImages(){
var objs = document.getElementsByTagName("img");
var imgScr = '';
for(var i=0;i<objs.length;i++){
imgScr = imgScr + objs[i].src + '+';
};
return imgScr;
};";
[webView stringByEvaluatingJavaScriptFromString:jsGetImages];//注入js方法
NSString *urlResurlt = [webView stringByEvaluatingJavaScriptFromString:@"getImages()"];
mUrlArray = [NSMutableArray arrayWithArray:[urlResurlt componentsSeparatedByString:@"+"]];
if (mUrlArray.count >= 2) {
[mUrlArray removeLastObject];
}
DLog(@"%@",mUrlArray);
}
其中mUrlArray为可变数组,用来盛放web中的图片url组。