xcode 解析来自 webview 的 html id 数据

Posted

技术标签:

【中文标题】xcode 解析来自 webview 的 html id 数据【英文标题】:xcode parse html id data from webview 【发布时间】:2012-04-17 16:30:34 【问题描述】:

一个 html 文件被加载到 webview 中,并且该 html 包含一个 div,如:

<div id="test">hello</div>

ios代码如下。但是我总是收到一个空值。我错过了什么?谢谢

-(void)webViewDidFinishLoad:(UIWebView *)webView 

    NSString *body = [self.webView stringByEvaluatingjavascriptFromString:
                      @"document.getElementById('test').value"];

    NSLog(@"received data: %@", body);


【问题讨论】:

【参考方案1】:

这有点笨拙,但您可以通过以下方式获取文本值(这是您当前使用的元素节点的文本节点和子节点)...

document.getElementById('test').firstChild.data

希望有帮助

【讨论】:

以上是关于xcode 解析来自 webview 的 html id 数据的主要内容,如果未能解决你的问题,请参考以下文章