简体   繁体   English

使用stringByEvaluatingJavaScriptFromString document.getElementsByClassName从UIWebView获取数据

[英]Get data from UIWebView with stringByEvaluatingJavaScriptFromString document.getElementsByClassName

I want to catch an image from a UIWebView . 我想从UIWebView捕获图像。 So I run the following code on the WebView where the website is completely loaded. 因此,我在完全加载网站的WebView上运行以下代码。

    NSString *test = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('first-carousel-item')[0].getAttribute('data-img');"];
    NSLog(@"test %@", test);

But the log writes: 但是日志写道:

Printing description of test: <object returned empty description>

The Javascript works well on the Chrome console. 该Javascript在Chrome控制台上运行良好。

if u want to catch anything from a webview don't forget to delegate it 如果您想从Web视图中捕获任何内容,请不要忘记委托它

[webView setDelegate:Self];

and when it uses the image use the webViewDidFinishLoad 当它使用图像时,请使用webViewDidFinishLoad

if u any more questions i here :D 如果您还有其他问题我在这里:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM