【问题标题】:How to get the span value from WebFrame in cocoa using objective c如何使用objective c从可可中的WebFrame获取跨度值
【发布时间】:2013-11-11 13:00:20
【问题描述】:

我正在使用下面的代码在加载 web 视图后获取 html 值并能够以字符串形式获取响应

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{   
    WebDataSource *source = [frame dataSource];
    NSData *data = [source data];
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];   
    NSLog(@"String ::: %@",str);
}

这是我在 str 中的 html 响应:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link rel="stylesheet" type="text/css" href="style.css" />        
            </head>
        <body>
        <div id="hidden" hidden="true">
            <span id="u-email">something@gmail.com</span>
        </div>
    </body>
    </html>

我需要获取 span 的隐藏值:

例如:

<span id="u-email">something@gmail.com</span>

如何在cocoa框架的Webview中获取span值(something@gmail.com)

请指教!

【问题讨论】:

    标签: iphone objective-c cocoa webkit


    【解决方案1】:

    你可以试试stringByEvaluatingJavaScriptFromString

    例如

    NSString *function = [NSString stringWithFormat:@"document.getElementById('u-email').innerHTML"];
    NSString *result = [webView stringByEvaluatingJavaScriptFromString:function];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 2020-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多