举个例子:
//js的标签内容
<meta name="attach_title" content="">
<meta name="attach_url" content="">
//UIWebView获取方法
NSString *js = @"document.getElementsByName(\"attach_title\")[0].content";
NSString *attach_title = [self.webView stringByEvaluatingJavaScriptFromString:js];
js = @"document.getElementsByName(\"attach_url\")[0].content";
NSString *attach_url = [self.webView stringByEvaluatingJavaScriptFromString:js];
//WKWebView的获取方法
- (void)getWKwebViewCenterDic {
[self.wkWebView evaluateJavaScript:@"document.getElementsByName(\"attach_title\")[0].content" completionHandler:^(id result, NSError * _Nullable error) {
NSString *attach_title = @"";
if ([result isKindOfClass:[NSString class]]) {
attach_title = result;
}
}];
[self.wkWebView evaluateJavaScript:@"document.getElementsByName(\"attach_url\")[0].content" completionHandler:^(id result, NSError * _Nullable error) {
NSString *attach_url = @"";
if ([result isKindOfClass:[NSString class]]) {
attach_url = result;
}
}];
}
//获取所有的html
NSString *allHtml = @"document.documentElement.innerHTML";
//获取网页title
NSString *htmlTitle = @"document.title";