Manoj Arun S
Manoj Arun S

Reputation: 543

How to get the span value from WebFrame in cocoa using objective c

I'm using the below code to get the html value after the web view loaded and able to get the response in string

- (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);
}

Here's my html response in str :

<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">[email protected]</span>
        </div>
    </body>
    </html>

I would need to get the hidden value of span :

for ex :

<span id="u-email">[email protected]</span>

How to get the span value([email protected]) in Webview of cocoa framework ?

Please advice!

Upvotes: 0

Views: 225

Answers (1)

Gyani
Gyani

Reputation: 2241

you can try stringByEvaluatingJavaScriptFromString

e.g.

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

Upvotes: 1

Related Questions