我需要检查WKWebView的内容是否包含一个特定的字符串。我该怎么做呢?我没有在上面找到任何内容或数据属性。
发布于 2015-09-27 14:09:49
方法1:在目标C中进行
NSString *str = [NSString stringWithContentsOfURL:wkwebview.URL usedEncoding: NSUTF8StringEncoding error:nil];
NSRange range = [str rangeOfString:@"string to find"];
if (range.location != NSNotFound) {
//found
}方法2:在JQuery中执行
NSString *js = @"var htmlString = $('body').html().toString();
var index = htmlString.indexOf('string to find');
if (index != -1) {alert('found')}";
[wkWebView evaluateJavaScript:js completionHandler:nil];https://stackoverflow.com/questions/32805672
复制相似问题