gpt4 book ai didi

ios - UIWebView 源代码

转载 作者:行者123 更新时间:2023-11-29 00:56:32 28 4
gpt4 key购买 nike

我在按钮上有一个IBAction,其中包含以下代码,我尝试使用它来检索 UIWebView 的源代码:

- (IBAction)loadInAWebView:(id)sender {
[self.webView loadHTMLString:[NSString stringWithFormat:@"Hello: %@", _name.text] baseURL:nil];

NSString *yourHTMLSourceCodeString = [_webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerHTML"];

NSLog(@"%@", yourHTMLSourceCodeString);
}

上面代码的使用来 self 在这个链接中看到的引用:Getting the HTML source code of a loaded UIWebView .

但是,NSLog 函数始终返回以下内容:

<head></head><body></body>

这显然没有反射(reflect)我心目中的 UIWebView 的实际源代码:

<head></head><body>Hello, name</body>

确实,UIWebView 返回了“Hello, name”内容,但相关源代码却没有返回。

如何编辑上面的代码来检索真正的 UIWebView 源代码?

最佳答案

您需要实现 UIWebViewDelegate 方法
- (void)webViewDidFinishLoad:(UIWebView *)webView 并设置 self.webView.delegate = self;
将代码 NSString *yourHTMLSourceCodeString = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerHTML"]; 放入此方法

关于ios - UIWebView 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37575581/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com