ZennoLab

Automate everything

User Tools

Site Tools


Sidebar

Translations of this page:

en:addons:capmonster:areyouhumancaptcha

AreYouHuman Audio

CapMonster 2 software starting from 2.5.0.0 version allows to recognize are you human captcha. We have developed special module ZennoLab.AudioReCaptcha for this. When you get are you human captcha on a webpage, you should select audio recognition and send it to CapMonster.

Using in ZennoPoster

To send are you human catpcha from ZennoPoster (v.5.9.5.1 and higher) you should use the following snippet. Here is the code:

 
// Main settings
 
// waiting timeout
var waitTime = 1000;
// waiting timeout for canvas loading
var waitTimeCanvas = 2000;
// attempts to load element
var tryLoadElement = 60;
// display notifications about recognition progress
var needShowMessages = false;
 
// additional variables
 
// tab
var tab = instance.ActiveTab;
// audio file
var file = string.Empty;
// file has been deleted
var fileDeleted = true;
// answer to audio captcha
var answer = string.Empty;
// timeout exceeded
var timeout = false;
// error loading file
var fileLoadingError = false;
var usedURLs = new List<string>();
 
// Open the form with audio task
Action OpenAudioForm = () => {
	project.SendInfoToLog("Waiting canvas object loading", needShowMessages);
	for (int k = 0; k < tryLoadElement; k++)
	{
		// detecting area for click
		var canvas = tab.FindElementById("ayah-canvas-fg");
		if (!canvas.IsVoid)
		{
			System.Threading.Thread.Sleep(waitTimeCanvas);
			var p = canvas.DisplacementInTabWindow;
			var x1 = p.X + 312;
			var x2 = p.X + 316;
			var y1 = p.Y + 141;
			var y2 = p.Y + 148;
			// selecting random point
			Random random = new Random();
			var x = random.Next(x1, x2);
			var y = random.Next(y1, y2);
			// then clicking
			tab.MouseClick(x, y, "Left", "click");
			break;
		}
		else System.Threading.Thread.Sleep(waitTime);
		if (k == (tryLoadElement - 1)) timeout = true;
	}
};
 
// Downloading mp3-file
Action GetAudioFile= () => {
	var href = String.Empty;
	project.SendInfoToLog("Getting audio task", needShowMessages);
	for (int k = 0; k < tryLoadElement; k++)
	{
		var audioChallenge = tab.FindElementByAttribute("a", "id", "recaptcha_audio_download", "text", 0);
		// if found, getting link to audio file
		if (!audioChallenge.IsVoid)
		{
			href = audioChallenge.GetAttribute("href");
			break;
		}
		System.Threading.Thread.Sleep(waitTime);
		if (k == (tryLoadElement - 1)) timeout = true;
	}
 
	foreach (var usedUrl in usedURLs)
	{
		if (usedUrl.Contains(href))
			throw new Exception("new audio file is absent");
	}
	usedURLs.Add(href);
 
	project.SendInfoToLog("Downloading audio file", needShowMessages);
	try
	{
		var proxy = instance.GetProxy();
		var respType = ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.File;
		var timeoutRequest = 30000;
		var cookies = instance.GetCookie("google.com", true);
		var userAgent = project.Profile.UserAgent;
		var maxRedirectCount = 1;
		var downloadPath = project.Directory + "\\audiofiles";
		file = ZennoPoster.HttpGet(href, proxy, "UTF8", respType, timeoutRequest, cookies, userAgent, false, maxRedirectCount, null, downloadPath);
		fileDeleted = false;
	}
	catch (Exception ex)
	{
		throw new Exception("Faild to download audio file");
	}
};
 
Action Recognize= () => {
	project.SendInfoToLog("Recognizing", needShowMessages);
	try 
	{
		if (!File.Exists(file)) 
		{
			fileLoadingError = true;
			fileDeleted = true;
			return;
		}
		var bytes = File.ReadAllBytes(file);
		if (bytes.Length < 1024)
		{
			fileLoadingError = true;
			return;
		}
		string str = Convert.ToBase64String(bytes);
		var rc = ZennoPoster.CaptchaRecognition("CapMonster2.dll", str, "CapMonsterModule=ZennoLab.AudioReCaptcha&ParallelMode=true");
		answer = rc.Split(new [] {"-|-"}, StringSplitOptions.RemoveEmptyEntries)[0];
	} 
	finally 
	{
		if (File.Exists(file)) 
		{
			File.Delete(file);
			fileDeleted = true;
		}
	}
};
 
Action InputAnswer= () => {
	project.SendInfoToLog("Inserting answer", needShowMessages);
	if (!String.IsNullOrEmpty(answer) && answer != "sorry")
	{
		HtmlElement audioAnswerInput = tab.FindElementByAttribute("input:text", "id", "recaptcha_response_field", "text", 0);
		// if found
		if (!audioAnswerInput.IsVoid)
		{
			// inserting answer
			audioAnswerInput.SetValue(answer, "Full", false);
		}
		// pause
		System.Threading.Thread.Sleep(waitTime);
	}
	else throw new Exception("Answer not received");
};
 
// Verifying
Action SubmitAnswer= () => {
	// searching "Verify" button
	HtmlElement apply = tab.FindElementByAttribute("input:submit", "fulltag", "input:submit", "text", 0);
	if (!apply.IsVoid) apply.Click();
	// pause
	System.Threading.Thread.Sleep(waitTime);
};
 
Action CheckTimeOut= () => {
	if (timeout) throw new Exception("Waiting timeout for loading element has been exceeded");
};
 
// Recognizing captcha
OpenAudioForm();
GetAudioFile();
CheckTimeOut();
Recognize();
if (fileLoadingError) throw new Exception("error loading file");
CheckTimeOut();
InputAnswer();
CheckTimeOut();
if (!fileDeleted)
{
	if (File.Exists(file))
	{
		File.Delete(file);
		fileDeleted = true;
	}
}
SubmitAnswer();
return "ok";
en/addons/capmonster/areyouhumancaptcha.txt · Last modified: 2015/11/23 14:51 by afameless