Reputation: 543
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
Reputation: 2241
you can try stringByEvaluatingJavaScriptFromString
e.g.
NSString *function = [NSString stringWithFormat:@"document.getElementById('u-email').innerHTML"];
NSString *result = [webView stringByEvaluatingJavaScriptFromString:function];
Upvotes: 1