Я пытаюсь войти на сайт, который имеет html-форму с капчиной. Способ, которым я пытался это сделать, - это получить html формы входа в систему, показывая captcha пользователю, который поместит его в текстовое поле, а затем я попытаюсь отправить форму.AFNetworking и отправка html-формы с подтверждением пользователя captcha
Ошибка, которую я всегда получаю, является недействительным ключевым кодом, поэтому я предполагаю, что проблема заключается в том, что я получаю первый экземпляр, недействителен для второго ... Любые идеи, как я мог это сделать это?
Веб-страница Fanfiction, и я делаю это как персональный проект и вижу, могу ли я экспортировать свой список фаворитов и следовать.
Я делаю это, чтобы показать captcha пользователю.
NSURL *url = [NSURL URLWithString:@"https://www.fanfiction.net"];
self.httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
[self.httpClient getPath:@"/login.php" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
TFHpple * doc = [[TFHpple alloc] initWithHTMLData:responseObject];
NSArray * elements = [doc searchWithXPathQuery:@"//img[@id='xcaptcha']"];
TFHppleElement * element = [elements objectAtIndex:0];
[self.captchaView setImageWithURL:[NSURL URLWithString:[element objectForKey:@"src"]]];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { }];
И затем, whenthe пользователь ввел капчу в текстовое поле и нажал UIButton, я делаю это
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
kFFNMail, @"email",
kFFNPass, @"password",
self.captchaField.text, @"captcha",
nil];
NSURLRequest *postRequest = [self.httpClient multipartFormRequestWithMethod:@"POST"
path:@"/login.php"
parameters:params
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { }];
/*
// I think this is the same as the one before in this case
NSMutableURLRequest *postRequest = [self.httpClient requestWithMethod:@"POST"
path:@"/login.php"
parameters:params2];
*/
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:postRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
TFHpple * doc = [[TFHpple alloc] initWithHTMLData:responseObject];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { }];
[operation start];
Если имеет каких-либо указаний, я эту работу в рубиновым сценарий как это
require 'rubygems'
require 'mechanize'
require "highline/import"
a = Mechanize.new
a.get('https://www.fanfiction.net/login.php') do |page|
images = page.search("#xcaptcha")
a.get(images.first.attributes["src"]).save "captcha.jpg"
# I read the saved image,and enter the captcha code
captcha = ask "Input captcha: "
# Submit the login form
my_page = page.form_with(:action => '/login.php') do |f|
f.email = my_mail
f.password = my_pass
f.captcha = captcha
end.click_button
# already logged!
a.get('https://www.fanfiction.net/alert/story.php') do |page|
page.links.each do |link|
text = link.text.strip
next unless text.length > 0
puts text
end
end
end