gpt4 book ai didi

ios - 如何在 ios 中提取隐藏的输入 uiwebview?

转载 作者:行者123 更新时间:2023-11-29 12:34:13 24 4
gpt4 key购买 nike

我正在开发一个将 HTML 页面加载到 uiwebview 的应用程序 - 该 html 文件包含许多字段,我需要获取 3 个字段并将其传递给 Web 服务

这是我的 HTML 页面:

<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">

我需要捕获其中已经存在的 myId、名字和状态值。

这里是我的示例代码:

- (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"];

编辑代码: NSString* value = [网页 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);

我的O/P:
值==
我的Id=

最佳答案

这是一些不规则但有效的方法,试试这个

- (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"];

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:@""];

value=[value stringByReplacingOccurrencesOfString:@"><input type=\"hidden\" name=\"status\" value=\"failure\">" withString:@""];

value=[value stringByReplacingOccurrencesOfString:@"name=\"first name\"" withString:@""];

value=[value stringByReplacingOccurrencesOfString:@"><input type=\"hidden\" " withString:@""];

value=[value stringByReplacingOccurrencesOfString:@"\"" withString:@""];

NSArray *items = [value componentsSeparatedByString:@" "];

NSString *myId = [items objectAtIndex:0]; // pass this value to server
NSString *name = [items objectAtIndex:1];

name=[name stringByReplacingOccurrencesOfString:@"value=" withString:@""]; // pass this value to server


NSLog(@"valkue==%@",value);
NSLog(@"myId=%@",myId);
NSLog(@"name=%@",name);

你的名字是

valkue==123654 value=xxxxx
myId=123654
name=xxxxx

关于ios - 如何在 ios 中提取隐藏的输入 uiwebview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26796197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com