美文网首页
WKWebview和UIWebview获取html中的标签

WKWebview和UIWebview获取html中的标签

作者: 关羽007 | 来源:发表于2019-03-07 14:12 被阅读0次

举个例子:

//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";

相关文章

网友评论

      本文标题:WKWebview和UIWebview获取html中的标签

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