Am developing an app which load a HTML page into uiwebview - that html file contains many fields i need to fetch 3 fields and pass it to web services
Here is my HTML page :
<form name="frmPostBack" id="frmPostBack" action="failure" method="post" style="display:none;">
<input type="hidden" name="myId" value="123654">
<input type="hidden" name="first name" value="xxxxx">
<input type="hidden" name="status" value="failure">
i need to capture myId,first name and status values which already present in it.
here my sample code :
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSCachedURLResponse *resp = [[NSURLCache sharedURLCache]cachedResponseForRequest:webpage.request];
NSString *yourHTMLSourceCodeString = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerHTML"];
NSLog(@"%@",[(NSHTTPURLResponse*)resp.response allHeaderFields]);
NSLog(@"%@",yourHTMLSourceCodeString);
NSString* value = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('myId').value"];
Edited Code : NSString* value = [webpage stringByEvaluatingJavaScriptFromString:@"document.getElementById('myId').value"];
NSRange r;
while ((r = [value rangeOfString:@"<form name=\"frmPostBack\" id=\"frmPostBack\" action=\"failure\" method=\"post\" style=\"display:none;\"> <input type=\"hidden\" name=\"myId\" value=\"" options:NSRegularExpressionSearch]).location != NSNotFound)
value = [value stringByReplacingCharactersInRange:r withString:@""];
NSArray *items = [value componentsSeparatedByString:@" "];
NSString *myId = [items objectAtIndex:0];
NSLog(@"valkue==%@",value);
NSLog(@"myId=%@",myId);
my O/P :
valkue==
myId=