Инструменты пользователя

Инструменты сайта


ru:addons:capmonster:rc-audio

Различия

Здесь показаны различия между двумя версиями данной страницы.

Ссылка на это сравнение

Both sides previous revision Предыдущая версия
Следущая версия
Предыдущая версия
ru:addons:capmonster:rc-audio [2017/02/27 13:19]
afameless
ru:addons:capmonster:rc-audio [2021/01/23 21:23] (текущий)
sergodjan
Строка 4: Строка 4:
 В программе будет доступен модуль ZennoLab.AudioReCaptcha. Работает это так: когда на странице встречается ReCaptcha, нужно выбрать распознавание через аудиозапись и отправить ее в CapMonster.\\ В программе будет доступен модуль ZennoLab.AudioReCaptcha. Работает это так: когда на странице встречается ReCaptcha, нужно выбрать распознавание через аудиозапись и отправить ее в CapMonster.\\
 \\ \\
-Принцип работы:​\\+Принцип работы:​\\ ​
 {{:​ru:​addons:​capmonster:​audiorc.png?​nolink|}} {{:​ru:​addons:​capmonster:​audiorc.png?​nolink|}}
  
Строка 25: Строка 25:
 // need to check answer'​s correctness // need to check answer'​s correctness
 var needToCheck = true; var needToCheck = true;
-// count of associations need to click in task with associations 
-var countAssociations = 4; 
    
 // Additional variables // Additional variables
Строка 40: Строка 38:
 // answer to audio captcha // answer to audio captcha
 var answer = string.Empty;​ var answer = string.Empty;​
-// new type ReCaptcha2 
-var isNewView = true; 
 // ReCaptcha 1 // ReCaptcha 1
 var isRecaptcha1 = false; var isRecaptcha1 = false;
Строка 49: Строка 45:
 var fileLoadingError = false; var fileLoadingError = false;
 var usedURLs = new List<​string>​();​ var usedURLs = new List<​string>​();​
-// task with associations 
-var isAssociationsTask = false; 
 var isFirstAttempt = true; var isFirstAttempt = true;
 var coincidenceReCaptcha2Index = -1; var coincidenceReCaptcha2Index = -1;
-  
-  
-Action FindAssociations= () => { 
- // getting task 
- var associationsTask = tab.FindElementByAttribute("​div",​ "​class",​ "​rc-text-desc-wrapper",​ "​regexp",​ 0); 
- if (!associationsTask.IsVoid) 
- { 
- var phraseSplit = associationsTask.GetAttribute("​innerhtml"​).Split(new []{"<​span>",​ "</​span>"​},​ StringSplitOptions.None);​ 
- if (phraseSplit.Length == 3) 
- { 
- var phrase = phraseSplit[1];​ 
- if (phrase != string.Empty) 
- { 
- var table = tab.FindElementByAttribute("​table",​ "​class",​ "​rc-text-choices",​ "​text",​ 0); 
- if (!table.IsVoid) 
- { 
- var tableElems = table.FindChildrenByTags("​td"​);​ 
-  
- if (tableElems.Count > 0) 
- { 
- var variants = new Dictionary<​string,​ HtmlElement>​();​ 
- var words = new List<​string>​();​ 
- foreach(var elem in tableElems) 
- { 
- var text = elem.GetAttribute("​innertext"​);​ 
- variants.Add(text,​ elem); 
- words.Add(text);​ 
- } 
-  
- project.SendInfoToLog("​Recognizing text task", needShowMessages);​ 
-  
- var requestString = string.Format("​{0}:​{1}",​ phrase, string.Join(";",​ words)); 
-  
- var imageStr = Convert.ToBase64String(new Byte[0]); 
-  
- var rc = ZennoPoster.CaptchaRecognition("​CapMonster2.dll",​ imageStr , string.Format("​Task={0}&​CapMonsterModule=ZennoLab.ReCaptchaAssociation",​ requestString));​ 
- var cmAnswer = rc.Split(new [] {"​-|-"​},​ StringSplitOptions.RemoveEmptyEntries)[0];​ 
- if (string.IsNullOrEmpty(cmAnswer) || cmAnswer == "​sorry"​) 
- { 
- var reload = tab.FindElementByAttribute("​div",​ "​id",​ "​recaptcha-reload-button",​ "​regexp",​ 0); 
- if (!reload.IsVoid) 
- reload.Click();​ 
- return;​ 
- } 
-  
- var answers = cmAnswer.Split(new []{";"​},​ StringSplitOptions.None);​ 
-  
- for (int i = 0; i < countAssociations;​ i++) 
- { 
- if (i < answers.Length) 
- { 
- variants[answers[i]].Click();​ 
- System.Threading.Thread.Sleep(500);​ //pause 
- } 
- } 
- } 
- } 
- } 
- } 
- } 
-}; 
    
 // Searching audio button element // Searching audio button element
Строка 136: Строка 69:
 Action OpenAudioTask= () => { Action OpenAudioTask= () => {
  project.SendInfoToLog("​Loading audio task", needShowMessages);​  project.SendInfoToLog("​Loading audio task", needShowMessages);​
- if (isNewView) + //checking task type in the form 
-+ var task = tab.FindElementByAttribute("​div",​ "​class",​ "​rc-imageselect-desc-wrapper",​ "​regexp",​ 0); 
- //checking task type in the form + if (!task.IsVoid) TryOpenAudioForm();​ // graphic task has been found, then loading audio
- var task = tab.FindElementByAttribute("​div",​ "​class",​ "​rc-imageselect-desc-wrapper",​ "​regexp",​ 0); +
- if (!task.IsVoid) TryOpenAudioForm();​ // graphic task has been found, then loading audio +
-+
- else +
-+
- var elem = tab.FindElementByAttribute("​input:​submit",​ "​class",​ @"​fbc-button-audio\ fbc-button",​ "​regexp",​ 0); +
- if (!elem.IsVoid) elem.Click();​  +
-  +
- tab.WaitDownloading();​ +
- var errorElem = tab.FindElementByAttribute("​div",​ "​class",​ "​fbc-message",​ "​regexp",​ 0); +
- if (!errorElem.IsVoid) +
-+
- var attr = errorElem.GetAttribute("​innertext"​);​ +
- if (attr.Contains("​Please enable JavaScript and/or update your browser to get an audio challenge"​)) +
-+
- throw new Exception("​Can'​t open audio form, try to change userAgent"​);​ +
-+
-+
- }+
 }; };
    
Строка 191: Строка 105:
  for (int k = 0; k < tryLoadElement;​ k++)  for (int k = 0; k < tryLoadElement;​ k++)
  {  {
- // searching coincidence index of recaptcha elements 
  VisibleIndexReCaptchaDefinition();​  VisibleIndexReCaptchaDefinition();​
- if (coincidenceReCaptcha2Index < 0)+ if (coincidenceReCaptcha2Index < 0) coincidenceReCaptcha2Index = 0; 
 +  
 + // поиск кнопки "Я не робот"​ 
 + HtmlElement notRobot = tab.FindElementByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp",​ coincidenceReCaptcha2Index);​ 
 +  
 + // кнопка существует 
 + if (!notRobot.IsVoid)
  {  {
- // checking if ReCaptcha 1 audio button exists + // клик по кнопке 
- HtmlElement r1 = tab.FindElementById("​recaptcha_switch_audio"​); + notRobot.Click(); 
- if (!r1.IsVoid) + System.Threading.Thread.Sleep(waitTime); // подождём немного
-+
- r1.Click(); +
- isRecaptcha1 = true; +
- break;​ +
- }+
    
- // checking ReCaptcha2 type + // если ввод каптчи не требуется 
- var ​elem = tab.FindElementByAttribute("​input:​submit", "​class", ​@"fbc-button-audio\ fbc-button", "​regexp", ​0); + var ​check = tab.FindElementByAttribute("​div", "​class",​ "recaptcha-checkbox-checkmark", "​regexp", ​coincidenceReCaptcha2Index); 
- if (!elem.IsVoid)+ if (!check.IsVoid)
  {  {
- isNewView ​= false; + if (check.OuterHtml.Contains("​style=\"​\""​)) 
- break;+
 + success = true; 
 + timeout ​= false; 
 + break; 
 + }
  }  }
  }  }
- else 
- { 
- // searching "​I'​m not robot" checkbox 
- var notRobot = tab.FindElementByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp",​ coincidenceReCaptcha2Index);​ 
- // if found 
- if (!notRobot.IsVoid) 
- { 
- // checking checkbox 
- notRobot.Click();​ 
- // pause 
- System.Threading.Thread.Sleep(waitTime);​ 
    
- // if entering captcha is not required + // Форма существует 
- var check = tab.FindElementByAttribute("​div",​ "​class",​ "recaptcha-checkbox-checkmark", "​regexp",​ 0); + var loadedForm ​= tab.FindElementByAttribute("​div",​ "​class",​ "primary-controls", "​regexp",​ 0); 
- if (!check.IsVoid) + if (!loadedForm.IsVoid) 
- + break;
- if (check.OuterHtml.Contains("​style=\"​\""​)) +
-+
- success = true; +
- break; +
-+
- }+
    
- // waiting when form will be loaded + // checking if ReCaptcha 1 audio button exists 
- for (int j = 0; j < tryLoadElement;​ j++) + HtmlElement r1 = tab.FindElementById("recaptcha_switch_audio"); 
-+ if (!r1.IsVoid) 
- var loadedForm ​= tab.FindElementByAttribute("div", "​class",​ "​primary-controls",​ "​regexp",​ 0); +
- if (!loadedForm.IsVoid) ​break; + r1.Click(); 
- else System.Threading.Thread.Sleep(waitTime); // waiting when element will be loaded + isRecaptcha1 ​= true; 
- if (j == (tryLoadElement - 1)) timeout ​= true; + break;
- +
- break; +
-  +
- }+
  }  }
 +
 + // подождём загрузки элементов
 + System.Threading.Thread.Sleep(waitTime);​
  if (k == (tryLoadElement - 1)) timeout = true;  if (k == (tryLoadElement - 1)) timeout = true;
  }  }
Строка 272: Строка 172:
  else  else
  {  {
- if (isNewView)+ if (isFirstAttempt)
  {  {
- if (isFirstAttempt) + isFirstAttempt = false;
-+
- isFirstAttempt = false; +
-+
- else +
-+
- var reload = tab.FindElementById("​recaptcha-reload-button"​);​ +
- if (!reload.IsVoid) +
-+
- reload.Click();​ +
- tab.WaitDownloading();​ +
-+
-+
-  +
- var audioChallenge = tab.FindElementByAttribute("​a",​ "​class",​ "​rc-audiochallenge-download-link",​ "​regexp",​ 0); +
- // if found, getting link to audio file +
- if (!audioChallenge.IsVoid) +
-+
- href = audioChallenge.GetAttribute("​href"​);​ +
- isAssociationsTask = false; +
- break;​ +
-+
- else +
-+
- isAssociationsTask = true; +
- return;​ +
-+
- System.Threading.Thread.Sleep(waitTime);​ // waiting when form will be loaded+
  }  }
  else  else
  {  {
- var ​audioChallenge ​= tab.FindElementByAttribute("audio",​ "​class",​ "fbc-audio-controls", "​regexp",​ 0); + var ​reload ​= tab.FindElementById("recaptcha-reload-button"); 
- // if found, getting link to audio file + if (!reload.IsVoid)
- if (!audioChallenge.IsVoid)+
  {  {
- href = audioChallenge.FindChildByAttribute("​source",​ "​src",​ "​.mp3",​ "​text",​ 0).GetAttribute("​src"​); + reload.Click(); 
- href = "​https://​www.google.com"​ + href; + tab.WaitDownloading();
- break;+
  }  }
- else System.Threading.Thread.Sleep(waitTime);​ // waiting when element will be loaded 
  }  }
 +
 + var audioChallenge = tab.FindElementByAttribute("​a",​ "​class",​ "​rc-audiochallenge-tdownload-link",​ "​regexp",​ 0);
 + // if found, getting link to audio file
 + if (!audioChallenge.IsVoid)
 + {
 + href = audioChallenge.GetAttribute("​href"​);​
 + break;
 + }
 + System.Threading.Thread.Sleep(waitTime);​ // waiting when form will be loaded
  }  }
  if (k == (tryLoadElement - 1)) timeout = true;  if (k == (tryLoadElement - 1)) timeout = true;
Строка 403: Строка 282:
  else  else
  {  {
- if (isNewView) ​audioAnswerInput = tab.FindElementByAttribute("​input:​text",​ "​id",​ "​audio-response",​ "​regexp", 0); + audioAnswerInput = tab.FindElementByAttribute("​input:​text",​ "​id",​ "​audio-response",​ "​regexp",​ 0);
- else audioAnswerInput = tab.FindElementByAttribute("​input:​text",​ "​id",​ "​response",​ "text", 0);+
  }  }
    
Строка 423: Строка 301:
 Action SubmitAnswer= () => { Action SubmitAnswer= () => {
  // searching "​Verify"​ button  // searching "​Verify"​ button
- HtmlElement ​apply = null; + HtmlElement apply = tab.FindElementById("​recaptcha-verify-button"​);​
- if (isNewView) ​apply = tab.FindElementById("​recaptcha-verify-button"​); +
- else apply = tab.GetDocumentByAddress("​0;​_0"​).FindElementByTag("​form",​ 0).FindChildByAttribute("​input:​submit",​ "​fulltag",​ "​input:​submit",​ "​text",​ 0);+
    
  if (!apply.IsVoid) apply.Click();​  if (!apply.IsVoid) apply.Click();​
Строка 433: Строка 309:
  System.Threading.Thread.Sleep(waitTime);​  System.Threading.Thread.Sleep(waitTime);​
 }; };
-  + 
-// Checking if answer is correct for old ReCaptcha +// Checking if answer is correct for ReCaptcha ​2 
-Action ​CheckOldView= () => { +Action ​Check= () => { 
- // checking if there is recognition mistake + project.SendInfoToLog("Verifying answer", ​needShowMessages); 
- HtmlElement he = tab.GetDocumentByAddress("0;​_0"​).FindElementByTag("​form", ​0).FindChildByAttribute("​div",​ "​class",​ "​fbc-error",​ "​regexp",​ 0); + tab.WaitDownloading(); 
- if (!he.IsVoid +
-+
- return+
- +
-  +
- string txt = string.Empty;​ +
- // searching text to insert+
  for (int k = 0; k < tryLoadElement;​ k++)  for (int k = 0; k < tryLoadElement;​ k++)
  {  {
- HtmlElement heGetText ​= tab.FindElementByAttribute("​textarea", "dir", "ltr", "​regexp",​ 0); + System.Threading.Thread.Sleep(waitTime);​ 
- if (!heGetText.IsVoid)+  
 + var checkAnswer = tab.FindElementByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp",​ coincidenceReCaptcha2Index);​ 
 +  
 + // проверка исчезновения формы 
 + var loadedForm ​= tab.FindElementByAttribute("​div", "class", "primary-controls", "​regexp",​ 0); 
 + if (loadedForm.IsVoid)
  {  {
- txt heGetText.GetAttribute("​value"​)+ success ​true
- break; + break;
  }  }
- else ​+ else
  {  {
- System.Threading.Thread.Sleep(waitTime); // pause + if (checkAnswer.IsVoid
- continue;+ break;
  }  }
- if (k == (tryLoadElement - 1)) timeout = true; +  
-+ var recaptchas ​= tab.FindElementsByAttribute("div", "class", "​recaptcha-checkbox-checkmark", "​regexp"​);​ 
-  + if (recaptchas.Count == 0)
- // searching where to insert text +
- for (int k = 0; k < tryLoadElement;​ k++) +
- { +
- HtmlElement hePutText ​= tab.FindElementByAttribute("textarea", "id", "g-recaptcha-response", "​regexp"​, 0); +
- if (!hePutText.IsVoid)+
  {  {
- hePutText.SetValue(txt,​ "​None",​ false)+ success = true
- break; + return;
  }  }
- else  +  
-+
- System.Threading.Thread.Sleep(waitTime);​ // pause +
- continue;​ +
-+
- if (k == (tryLoadElement - 1)) timeout = true; +
-+
-  +
- // pressing "​Verify"​ +
- for (int k = 0; k < tryLoadElement;​ k++) +
-+
- var submit = tab.FindElementByAttribute("​input:​submit",​ "​fulltag",​ "​input:​submit",​ "​regexp",​ 0); +
- if (!submit.IsVoid) +
-+
- submit.Click();​ +
- break; +
-+
- else  +
-+
- System.Threading.Thread.Sleep(waitTime);​ // pause +
- continue;​ +
-+
- if (k == (tryLoadElement - 1)) timeout = true; +
-+
- success = true; +
-}; +
-  +
-// Checking if answer is correct for ReCaptcha 2 +
-Action Check= () => { +
- project.SendInfoToLog("​Verifying answer",​ needShowMessages);​ +
- tab.WaitDownloading();​ +
- var recaptchas = tab.FindElementsByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp"​);​ +
- if (recaptchas.Count == 0) +
-+
- success = true; +
- return; +
-+
-  +
- for (int k = 0; k < tryLoadElement;​ k++) +
-+
- var checkAnswer = tab.FindElementByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp",​ coincidenceReCaptcha2Index);​+
  if (!checkAnswer.IsVoid)  if (!checkAnswer.IsVoid)
  {  {
Строка 520: Строка 350:
  }  }
  if (k == (tryLoadElement - 1)) timeout = true;  if (k == (tryLoadElement - 1)) timeout = true;
- System.Threading.Thread.Sleep(waitTime);​ 
  }  }
 }; };
Строка 536: Строка 365:
  if (timeout) break;  if (timeout) break;
    
- if (isAssociationsTask)+ Recognize();​ 
 + if (fileLoadingError
  {  {
- FindAssociations();+ fileLoadingError = false; 
 + continue;
  }  }
- else+ if (timeout) break; 
 + InputAnswer();​ 
 + if (timeout) break; 
 + if (!fileDeleted)
  {  {
- Recognize();​ + if (File.Exists(file))
- if (fileLoadingError+
  {  {
- fileLoadingError = false+ File.Delete(file)
- continue;+ fileDeleted = true;
  }  }
- if (timeout) break; 
- InputAnswer();​ 
- if (timeout) break; 
- if (!fileDeleted) 
- { 
- if (File.Exists(file)) 
- { 
- File.Delete(file);​ 
- fileDeleted = true; 
- } 
- } 
-  
- if (isRecaptcha1) return "​ok";​ 
  }  }
 +
 + if (isRecaptcha1) return "​ok";​
  SubmitAnswer();​  SubmitAnswer();​
    
Строка 567: Строка 389:
    
  if (timeout) break;  if (timeout) break;
- if (!isNewView) CheckOldView();​ + Check();
- else Check();+
  if (success) return "​ok";​  if (success) return "​ok";​
 } }
ru/addons/capmonster/rc-audio.1488201588.txt.gz · Последние изменения: 2017/02/27 13:19 — afameless