gpt4 book ai didi

iphone - 在 UIWebView 中打开的 HTML 页面中自动填充用户名和密码

转载 作者:行者123 更新时间:2023-12-03 21:03:49 34 4
gpt4 key购买 nike

使用 UIWebView 自动填充数据时如何使用 RegsEx 查找登录表单?

我使用以下代码来获取所有表单数据:

int NoOfForms = [[self.browser stringByEvaluatingJavaScriptFromString:@"document.forms.length"] intValue];

NSMutableArray *formData = [[NSMutableArray alloc] initWithCapacity:0];

for (int i = 0 ; i < NoOfForms ; i++)
{
// total number of elements in each form
int elementsInForm = [[self.browser stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.forms[%d].elements.length",i]] intValue];
for (int j = 0; j < elementsInForm; j++)
{
// element id of each element
NSString *elementID = [NSString stringWithFormat:@"document.forms[%d].elements[%d].id",i,j];
// element value of each element
NSString *elementValue = [NSString stringWithFormat:@"document.forms[%d].elements[%d].value",i,j];

// dictionary for all values of each element
NSDictionary *elementData = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:i],@"form No",
[NSNumber numberWithInt:j],@"element No",
[self.browser stringByEvaluatingJavaScriptFromString:elementID],@"elementID",
[self.browser stringByEvaluatingJavaScriptFromString:elementValue],@"elementValue",nil];

// add each element data to a mutable array.
[formData addObject:elementData];
}
}

并使用以下代码将数据放回到各自的字段中:

for (int i = 0 ; i < [dataArray count]; i++) 
{
NSDictionary *elementDict = [dataArray objectAtIndex:i];

int formNumber = [[elementDict objectForKey:@"form No"] intValue];
int elementNumber = [[elementDict objectForKey:@"element No"] intValue];
NSString *formElementID = [elementDict objectForKey:@"elementID"];
NSString *formElementValue = [elementDict objectForKey:@"elementValue"];

if ([[self.browser stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.forms[%d].elements[%d].id",formNumber,elementNumber]] isEqualToString:formElementID])
{
[self.browser stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.forms[%d].elements[%d].value='%@'",formNumber,elementNumber,formElementValue]];
}

}

现在我只想提交登录表单..如何找到它?

我还遇到一个问题:当我的代码将密码放入其字段时,某些网站(例如 mail.google.com)确实会发生这种情况,即它会清空密码字段。如何解决这个问题?

更新:目前我已经能够登录mail.google.com,但无法登录belleandclive.com。该网站是否对其登录表单实现了任何安全措施?

最佳答案

我想你可以根据表单数据或者表单id来判断哪个是登录表单,对吧?

因此,如果登录表单id为login-form,则可以使用以下代码来提交:

NSString * js = @"document.getElementById('login-form').submit()";
[self.webview stringByEvaluatingJavaScriptFromString:js];

也可以根据表单数据判断哪个索引是登录表单来提交表单:

int index = ....// your judge code to get index
NSString * js = [NSString stringWithFormat:@"document.forms[%d].submit()", index];
[self.webview stringByEvaluatingJavaScriptFromString:js];

关于iphone - 在 UIWebView 中打开的 HTML 页面中自动填充用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10039602/

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