User Tools

Site Tools


Sidebar



en:objects:rucaptcha:functional:recognize_click_captcha

recognize_click_captcha

recognize_click_captcha($filename,$textinstructions); - recognize a captcha where you need to click somewhere (click captcha). For more information, see here

It uses the following object fields :
  • $this->api_key - API key

    The function accepts parameters as input:

  • $filename – path to the captcha image
  • $textinstructions – text of what you need to select in the image in UTF-8 encoding. This parameter is optional, if the image is clear where to click - you can not send

    After testing, the function returns the result of its work to the script :
  • The result of recognition is a captcha string in the form OK|coordinate:x=39,y=59;x=252,y=72 ,where - x and y coordinates of captcha clicks or a code string with an error response:
  • ERROR_KEY_DOES_NOT_EXIST - you used an invalid captcha key in the request
  • ERROR_WRONG_ID_FORMAT - invalid captcha ID, only digits are accepted
  • ERROR_CAPTCHA_UNSOLVABLE - 5 different employees couldn't solve the captcha

    PHP example:

    <?php $xhe_host = "127.0.0.1:7010";
     
    //РїРѕРґРєР "СЋС ‡ РёРј РѕР ± ъект РґР "СЏ СѓРїСЂР ° РІР» ения СЌРјСѓР »СЏС‚РѕСЂРѕРј, есл Рё РееРРРРР Рё ее РµРРРРРё еееРРРР
    if(!isset($path))
      $path = "../../../Templates/xweb_human_emulator.php";
    require($path);
     
    //РЅР ° С ‡ Р ° Р »Р *
    echo "<hr> <font color = blue> rucaptcha->".basename(__FILE__)."</font> <hr>";
     
    //API РєР »СЋС ‡
    $rucaptcha->api_key = "";
     
    //1
    echo "1.Перейдем РЅР ° РїРѕР» РёРіРѕРЅ: ";
    echo $browser->navigate("https://www.google.com/recaptcha/api2/demo")."<br>";
     
    //2
    echo("2.РќР ° жмем СЏ РЅРµ СЂРѕР ± РѕС‚: ");
    while(!$div->get_by_attribute("class", "recaptcha-checkbox-checkmark", false, 0)->is_visibled()) sleep(1);
    echo $check = $div->get_by_attribute("class", "recaptcha-checkbox-checkmark", false, 0)->send_mouse_click(mt_rand(1,4), mt_rand(1,4))." n";
     
    //3
    echo "3.РРѕС… СЂР ° РЅРёРј РєР ° СЂС‚РёРЅРєС Рё РІРѕРїСЂРѕСЃ:";
    while(!$image->get_by_src("www.google.com/recaptcha/api2/payload", false, 1)->is_visibled()) sleep(1);
    sleep(3);
    echo $image->screenshot_by_src("test \ tmp.jpeg", "www.google.com/recaptcha/api2/payload",false,1)." ";
    //СЃРѕС… СЂР ° РЅРёРј С‚РµРєСЃС ‚
    echo $describtion = explode(" n", $div->get_inner_text_by_attribute("class", "imageselect-desc", false, 1)) [0];
     
    //4
    //преоР± СЂР ° Р · уемв UTF РґР »СЏ отпрР° РІРєРё РІ сервис СЂСѓРєР ° РїС ‡ Рё
    $describtion = iconv("windows-1251", "utf-8", $describtion);
    //СЂР ° СЃРїРѕР · РЅР ° ем РєР ° РїС ‡ Сѓ - РєР ° Рє ту РіРґРµ РЅСѓР¶РЅРѕ сделР° ть РєР» РёРєРё
    $solution = $rucaptcha->recognize_click_captcha("test \ tmp.jpeg", $describtion);
     
    //five
    echo "5.РР" икнем РїРѕ РїРѕР "СѓС ‡ енны Рј РєРѕРѕСЂРґРёРЅР ° тР° Рј:  n  n ";
    if(strpos($solution, "coordinates:")!= - 1)
    {
    $solution = str_replace("coordinates:", "", $solution);
       $solution = str_replace(";", ",", $solution);
    $coords = explode(",", $solution);
       $image->get_by_src("www.google.com/recaptcha/api2/payload", false, 1)->focus();
    for($i = 0; $i <count($coords); $i + = 2)
    {
    $x = str_replace("x =", "", $coords [$i]);
    $y = str_replace("y =", "", $coords [$i + 1]);
    echo "click at(".$x."".$y."): РЅР ° РєР ° ртинке РєР ° РїС ‡ Ryo:";
    echo $image->get_by_src("recaptcha/api2/payload", false, 1)->send_mouse_move($x, $y)."";
    usleep(50,000);
    echo $image->get_by_src("recaptcha/api2/payload", false, 1)->send_mouse_click($x, $y)." n";
    usleep(mt_rand(300000,1000000));
    }
       echo " n";
    }
     
    $btn->click_by_id("recaptcha-verify-button", "1");
     
     
    //РєРѕРЅРµС †
    echo "<hr> <br>";
     
    //Quit
    $app->quit();
    ?>

    Python example:

    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
     
    xhe_host = "127.0.0.1:7013"
    from xweb_human_emulator import *
     
    # Start
    echo("<hr> <font color = blue> rucaptcha.xxxxxxxxx </font> <hr>")
     
    # API key
    rucaptcha.api_key = "448b2d538fef6c236092492a947af85b"
     
    # 1
    echo("1.Let's go to the polygon:")
    echo(browser.navigate("https://www.google.com/recaptcha/api2/demo"), "<br>")
     
    # 2
    echo("2.Click I'm not a robot:")
    while not div.get_by_attribute("class", "recaptcha-checkbox-checkmark", false, 0) .is_visibled():
        sleep(1)
    check = div.get_by_attribute("class", "recaptcha-checkbox-checkmark", false, 0) .send_mouse_click(4,4)
    echo(check, "
    ")
     
    # 3
    echo("3.Save the picture and the question:")
    while not image.get_by_src("www.google.com/recaptcha/api2/payload", false, 1) .is_visibled():
    sleep(1)
     
    sleep(3)
    echo(image.screenshot_by_src("test \ tmp.jpeg", "www.google.com/recaptcha/api2/payload",false,1)," ")
    # save the text
    desc = div.get_inner_text_by_attribute("class", "imageselect-desc", false, 1)
    desc = desc.split("
    ")
    description = desc [0] + "" + desc [1];
    echo(description, "<br>")
     
    # recognize captcha - as the one where you need to make clicks
    solution = rucaptcha.recognize_click_captcha("test \ tmp.jpeg", description)
     
    # 5 coordinates: x = 186, y = 64; x = 313, y = 72; x = 316, y = 198
    echo("5.Click on the obtained coordinates:
     
    ")
    if solution.find("coordinates:")!= - 1:
     
    solution = solution.replace("coordinates:", "")
    solution = solution.replace(";", ",")
    coords = solution.split(",")
    img = image.get_by_src("www.google.com/recaptcha/api2/payload", false, 1)
    img .focus()
    for i in range(0, len(coords), 2):
    x = coords [i] .replace("x =", "",)
    y = coords [i + 1] .replace("y =", "")
    echo("click at(" + x + "" + y + "): captcha on the picture:")
    echo(image.get_by_src("recaptcha/api2/payload", false, 1) .send_mouse_move(x, y), "")
    sleep(0.05)
    echo(image.get_by_src("recaptcha/api2/payload", false, 1) .send_mouse_click(x, y), "
    ")
    #usleep(mt_rand(300000,1000000)))
    echo("
    ")
     
    # end
    echo("<hr> <br>")
     
    # Quit
    app.quit()

    C# example:

    #region using
     
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
     
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
     
    #endregion
     
     class Program: XHEScript
     {
    static void Main(string [] args)
    {
    //init XHE
    server = "127.0.0.1:7010";
    InitXHE();
     
    //Start
    echo("<hr> <font color = blue> rucaptcha.recognize_click_captcha </font> <hr>");
     
    //API key
    rucaptcha.api_key = "448b2d538fef6c236092492a947af85b";
     
    //1
    echo("1.Let's go to the polygon:");
    echo(browser.navigate("https://www.google.com/recaptcha/api2/demo") + "<br>");
     
    //2
    echo("2.Let's click I'm not a robot:");
    while(!div.get_by_attribute("class", "recaptcha-checkbox-checkmark", 0, "0").is_visibled()) {sleep(1);}
     
    bool check = div.get_by_attribute("class", "recaptcha-checkbox-checkmark", 0, "0").send_mouse_click(4,4);
    echo(check.ToString() + "
    ");
     
    //3
    echo("3.Save the picture and the question:");
    while(!image.get_by_src("www.google.com/recaptcha/api2/payload", 0, "1").is_visibled()) {sleep(1);}
                sleep(3);
    image.screenshot_by_src("test \ tmp.jpeg", "www.google.com/recaptcha/api2/payload",0,"1");
    //save the text
                string sText = div.get_inner_text_by_attribute("class", "imageselect-desc", 0, "1");
    string description = sText.Split('
    ') [0];
                echo(description + "
    ");
     
    //4
    //convert to UTF for sending to rucapcha service
    //description = iconv("windows-1251", "utf-8", description);
    //recognize the captcha - as the one where you need to make clicks
    string solution = rucaptcha.recognize_click_captcha("test \ tmp.jpeg", description);
     
    //five
    echo("5.Click on the obtained coordinates:
     
    ");
    if(solution.IndexOf("coordinates:")!= - 1)
    {
    solution = solution.Replace("coordinates:", "");
    solution = solution.Replace(";", ",");
    string [] coords = solution.Split(',');
    image.get_by_src("www.google.com/recaptcha/api2/payload", 0, "1").focus();
    for(int i = 0; i <coords.Length; i + = 2)
    {
    string x = coords [i] .Replace("x =", "");
    string y = coords [i + 1] .Replace("y =", "");
    echo("click at(" + x + "" + y + "): on the captcha picture:");
    echo(image.get_by_src("recaptcha/api2/payload", 0, "1").send_mouse_move(Convert.ToInt32(x), Convert.ToInt32(y)) + "");
    sleep(5);
    echo(image.get_by_src("recaptcha/api2/payload", 0, "1").send_mouse_click(Convert.ToInt32(x), Convert.ToInt32(y)) + "
    ");
    sleep(3);
    }
    echo("
    ");
    }
     
     
    btn.click_by_id("recaptcha-verify-button", 1);
    //end
    echo("<hr> <br>");
     
    app.quit();
    }
    }

    Java Script example:

    //connect the object to control the emulator, if not already connected
    xhe_host = "127.0.0.1:7010";
    echo = require("../../../Templates JS/xweb_human_emulator.js");
     
    //Start
    echo("<hr> <font color = blue> rucaptcha.recognize_click_captcha </font> <hr>");
     
    //API key
    rucaptcha.api_key = "");
     
    //1 step
    echo("1.Let's go to the polygon:");
    echo(browser.navigate("http://www.humanemulator.net/poligon/image.html") + "<br>");
     
    //step 2
    echo("2.Recognize captcha using the rucaptcha.com service(as a selection of images):");
    echo(image.screenshot_by_src("tmp/1.jpg", "like_image", false) + "");
    echo(rucaptcha.recognize_click_captcha(debug.get_cur_script_folder()."tmp \ 1.jpg", "") + " n");
     
    //step 3
    echo("3.Display information:");
    echo(rucaptcha.get_last_capcha_filename() + "");
    echo(rucaptcha.get_last_capcha_id() + "");
    echo(rucaptcha.get_last_capcha_result() + "<br>");
     
    //step 4
    echo("4.Set the default recognition parameters:");
    echo(rucaptcha.set_default_params();
     
    //end
    echo("<hr> <br>");
     
    //Quit
    app.quit();
  • en/objects/rucaptcha/functional/recognize_click_captcha.txt · Last modified: 2026/08/05 22:47 (external edit)