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

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


ru:addons:capmonster:rc-audio

Различия

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

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

Both sides previous revision Предыдущая версия
Следущая версия
Предыдущая версия
ru:addons:capmonster:rc-audio [2016/08/24 09:30]
vladz старая ревизия восстановлена (2016/08/01 14:36)
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|}}
  
Строка 18: Строка 18:
 var waitTime = 1000; var waitTime = 1000;
 // recognition attempts // recognition attempts
-var tryRecognize = 3;+var tryRecognize = 10;
 // attempts to load element // attempts to load element
 var tryLoadElement = 60; var tryLoadElement = 60;
Строка 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;
-  +
-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
Строка 118: Строка 52:
  for (int k = 0; k < tryLoadElement;​ k++)  for (int k = 0; k < tryLoadElement;​ k++)
  {  {
- var audioButton = tab.FindElementByAttribute("​div",​ "​id", ​"​recaptcha-audio-button"​, "​regexp",​ 0);+ var audioButton = tab.FindElementById("​recaptcha-audio-button"​);​
  // if found  // if found
  if (!audioButton.IsVoid)  if (!audioButton.IsVoid)
Строка 135: Строка 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); 
 + if (!task.IsVoid) TryOpenAudioForm();​ // graphic task has been found, then loading audio 
 +}; 
 +  
 +Action VisibleIndexReCaptchaDefinition= () => { 
 + var recaptchaElementsGroup = tab.FindElementsByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp"​);​ 
 + int length = recaptchaElementsGroup.Elements.Length;​ 
 + if (length == 1)
  {  {
- //checking task type in the form + coincidenceReCaptcha2Index ​= 0; 
- var task tab.FindElementByAttribute("​div",​ "​class",​ "​rc-imageselect-desc-wrapper",​ "​regexp", ​0)+ return;
- if (!task.IsVoid) TryOpenAudioForm()// graphic task has been found, then loading audio+
  }  }
- else+  
 + for(int i = 0; i < length; i++)
  {  {
- var elem tab.FindElementByAttribute("​input:​submit",​ "​class",​ @"​fbc-button-audio\ fbc-button",​ "​regexp",​ 0)+ var element ​recaptchaElementsGroup.Elements[i]
- if (!elem.IsVoid) ​elem.Click(); + if (!element.IsVoid) 
 +
 + int x = element.DisplacementInTabWindow.X;​ 
 + int y = element.DisplacementInTabWindow.Y;
    
- tab.WaitDownloading();​ + var suspectVisibleElement ​= tab.GetElementFromPoint(xy).DisplacementInTabWindow
- var errorElem ​= tab.FindElementByAttribute("​div"​"​class",​ "​fbc-message",​ "​regexp",​ 0); + if (x == suspectVisibleElement.X && y == suspectVisibleElement.Y && element.Width != 0 && element.Height != 0 && x != 0 && y != 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"​);+ coincidenceReCaptcha2Index = i; 
 + break;
  }  }
  }  }
Строка 163: Строка 105:
  for (int k = 0; k < tryLoadElement;​ k++)  for (int k = 0; k < tryLoadElement;​ k++)
  {  {
- // searching ​"I'm not robot" ​checkbox + VisibleIndexReCaptchaDefinition();​ 
- var notRobot = tab.FindElementByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp", ​0); + if (coincidenceReCaptcha2Index < 0) coincidenceReCaptcha2Index = 0; 
- // if found+  
 + // поиск кнопки ​"Я не робот
 + HtmlElement ​notRobot = tab.FindElementByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp", ​coincidenceReCaptcha2Index); 
 +  
 + // кнопка существует
  if (!notRobot.IsVoid)  if (!notRobot.IsVoid)
  {  {
- // checking checkbox+ // клик по кнопке
  notRobot.Click();​  notRobot.Click();​
- // pause + System.Threading.Thread.Sleep(waitTime); ​// подождём немного
- System.Threading.Thread.Sleep(waitTime);​+
    
- // if entering captcha is not required + // если ввод каптчи не требуется 
- var check = tab.FindElementByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp", ​0);+ var check = tab.FindElementByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp", ​coincidenceReCaptcha2Index);
  if (!check.IsVoid)  if (!check.IsVoid)
  {  {
Строка 180: Строка 125:
  {  {
  success = true;  success = true;
 + timeout = false;
  break;  break;
  }  }
  }  }
 + }
    
- // waiting when form will be loaded + // Форма существует 
- for (int j = 0; j < tryLoadElement;​ j++) + var loadedForm = tab.FindElementByAttribute("​div",​ "​class",​ "​primary-controls",​ "​regexp",​ 0); 
- { + if (!loadedForm.IsVoid)
- var loadedForm = tab.FindElementByAttribute("​div",​ "​class",​ "​primary-controls",​ "​regexp",​ 0); +
- if (!loadedForm.IsVoid) ​break; +
- else System.Threading.Thread.Sleep(waitTime);​ // waiting when element will be loaded +
- if (j == (tryLoadElement - 1)) timeout = true; +
- }+
  break;  break;
- } +  
- else+ // checking if ReCaptcha 1 audio button exists 
 + HtmlElement r1 = tab.FindElementById("​recaptcha_switch_audio"​);​ 
 + if (!r1.IsVoid)
  {  {
- // checking if ReCaptcha 1 audio button exists + r1.Click(); 
- HtmlElement ​r1 = tab.FindElementById("​recaptcha_switch_audio"​); + isRecaptcha1 = true; 
- if (!r1.IsVoid) + break;
-+
- r1.Click();​ +
- isRecaptcha1 = true+
- break+
- +
-  +
- // checking ReCaptcha2 type +
- var elem = tab.FindElementByAttribute("​input:​submit",​ "​class",​ @"​fbc-button-audio\ fbc-button",​ "​regexp",​ 0); +
- if (!elem.IsVoid) +
-+
- isNewView = false; +
- break; +
-+
- System.Threading.Thread.Sleep(waitTime);​ //pause+
  }  }
 +
 + // подождём загрузки элементов
 + System.Threading.Thread.Sleep(waitTime);​
  if (k == (tryLoadElement - 1)) timeout = true;  if (k == (tryLoadElement - 1)) timeout = true;
  }  }
Строка 239: Строка 172:
  else  else
  {  {
- if (isNewView)+ if (isFirstAttempt)
  {  {
- if (isFirstAttempt) + isFirstAttempt = false;
-+
- isFirstAttempt = false; +
-+
- else +
-+
- var reload = tab.FindElementByAttribute("​div",​ "​id",​ "​recaptcha-reload-button",​ "​regexp",​ 0); +
- 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;
Строка 328: Строка 240:
  return;  return;
  }  }
 + 
 + var hexStringBuilder = new StringBuilder(2);​
 + for (var i = 0; i < 2; i++)
 + hexStringBuilder.AppendFormat("​{0:​x2}",​ bytes[i]);
 + 
 + var header_prefix = hexStringBuilder.ToString();​
 + if (!header_prefix.Equals("​ffe3"​))
 + {
 + fileLoadingError = true;
 +                        throw new Exception("​Your IP was banned!"​);​
 + return;
 + }
 + 
  string str = Convert.ToBase64String(bytes);​  string str = Convert.ToBase64String(bytes);​
  var rc = ZennoPoster.CaptchaRecognition("​CapMonster2.dll",​ str, "​CapMonsterModule=ZennoLab.AudioReCaptcha&​ParallelMode=true"​);​  var rc = ZennoPoster.CaptchaRecognition("​CapMonster2.dll",​ str, "​CapMonsterModule=ZennoLab.AudioReCaptcha&​ParallelMode=true"​);​
Строка 357: Строка 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);+
  }  }
    
Строка 377: Строка 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();​
Строка 387: Строка 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);​ +
- for (int k = 0; k < tryLoadElement;​ k++) +
-+
- var checkAnswer = tab.FindElementByAttribute("​div",​ "​class",​ "​recaptcha-checkbox-checkmark",​ "​regexp",​ 0);+
  if (!checkAnswer.IsVoid)  if (!checkAnswer.IsVoid)
  {  {
Строка 466: Строка 350:
  }  }
  if (k == (tryLoadElement - 1)) timeout = true;  if (k == (tryLoadElement - 1)) timeout = true;
- System.Threading.Thread.Sleep(waitTime);​ 
  }  }
 }; };
Строка 482: Строка 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();​
    
Строка 513: Строка 389:
    
  if (timeout) break;  if (timeout) break;
- if (!isNewView) CheckOldView();​ + Check();
- else Check();+
  if (success) return "​ok";​  if (success) return "​ok";​
 } }
Строка 534: Строка 409:
 var waitTime = 1000; var waitTime = 1000;
 // количество попыток распознать // количество попыток распознать
-var tryRecognize = 2;+var tryRecognize = 10;
 // количество попыток загрузить элемент // количество попыток загрузить элемент
 var tryLoadElement = 60; var tryLoadElement = 60;
ru/addons/capmonster/rc-audio.1472031025.txt.gz · Последние изменения: 2016/08/24 09:30 — vladz