views:

191

answers:

1

Basically my app has a UIwebView which loads a php script with input of user data. The script then uses printf(some info). This all works and it prints it right the UIWebView. Basically what I want to do is get that text (its all thats on the page) and save it as a string. Heres what I have tried so far.

NSString *str = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerHTML"]; // also used document.documentElement.innerText and outerHTML and some others none seem to work
NSLog(@"%@",str);

it returns nothing How exactly should I do this. I assume its pretty simple I just need the correct text to put in evaulatingjavascriptfromstring. I just can't find out what I should put in.

Thnx,

Bryan

+1  A: 

You can try two things. First one is:

NSString *str = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
NSLog(@"%@",str);

This will give you the HTML. Or if you don't want the HTML, just the actual text shown on the page then you can do:

NSString *str = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.textContent"];
NSLog(@"%@",str);

Hopefully this helps. Good luck.

Marcin