Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript my JS无法获取Objective-C中div的内容_Javascript_Iphone_Objective C_Cocoa - Fatal编程技术网

Javascript my JS无法获取Objective-C中div的内容

Javascript my JS无法获取Objective-C中div的内容,javascript,iphone,objective-c,cocoa,Javascript,Iphone,Objective C,Cocoa,我正在设法从我的Webview中检索一些文本。下面是我的HTML文件的示例 Template.html: <html> <body> <div id="content" contenteditable="true" style="font-family: Helvetica"> hello </div> </body> </html> 它一无所获!Xcode停

我正在设法从我的Webview中检索一些文本。下面是我的HTML文件的示例

Template.html:

<html>
<body>
        <div id="content" contenteditable="true" style="font-family: Helvetica">
            hello
            </div>
</body>
</html>
它一无所获!Xcode停止是为了支持这种类型的JS吗

请帮忙,非常感谢

---------编辑------------ 有关详细信息,请参见以下加载页面的方式:

NSBundle *bundle = [NSBundle mainBundle];
NSURL* temp = [bundle URLForResource:@"template" withExtension:@"html"];
[panel loadRequest:[NSURLRequest requestWithURL:temp]];

已加载的UIWebView内容将使用以下行获取

NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];
资料来源:


谢谢

我最后发现的其实是UIWebViewDelegate的问题

-(void)webViewDidFinishLoad:(UIWebView *)webView{
NSString *js = @"getContent();";//This function is used to get 
                                //the innerHTML of the document.
NSString* html = [panel stringByEvaluatingJavaScriptFromString:js];
L22(@"content HTML:",html);
}
这将为我提供div中的文本


在从网站中提取任何信息之前,始终确保网站已完全加载!:0)

document.getElementById('content')单独返回什么?恐怕它什么也不返回。好吧,innerHTML为空也就不足为奇了。模板缺少html结束标记的任何特殊原因?请检查您的出口。我打赌
panel
nil
@ronnyfm,这是Stackoverflow中的解析问题,我忘了在前面给它四个空格。这只是一个非常简单的例子,很遗憾,其他简单的JS无法阅读它@Neal,我检查过了,但面板本身返回为WebViews,但我在DIV中查找特定内容。到目前为止,我非常困惑,因为我使用的是从我在网上找到的Div中获取数据的标准方法。有什么建议吗?
-(void)webViewDidFinishLoad:(UIWebView *)webView{
NSString *js = @"getContent();";//This function is used to get 
                                //the innerHTML of the document.
NSString* html = [panel stringByEvaluatingJavaScriptFromString:js];
L22(@"content HTML:",html);
}