<?php function recognize( $filename, $apikey, $is_verbose = true, $sendhost = "antigate.com", $rtimeout = 10, $is_phrase = 0, $is_regsense = 1, $is_numeric = 0, $min_len = 4, $max_len = 4, $is_russian = 1) { if (!file_exists($filename)) { if ($is_verbose) echo "<b>file $filename not found</b>"; return false; } $fp=fopen($filename,"r"); if ($fp!=false) { $body=""; while (!feof($fp)) $body.=fgets($fp,1024); fclose($fp); $ext=strtolower(substr($filename,strpos($filename,".")+1)); } else { if ($is_verbose) echo "<b>could not read file $filename<b>"; return false; } if ($ext=="jpg") $conttype="image/pjpeg"; if ($ext=="gif") $conttype="image/gif"; if ($ext=="png") $conttype="image/png"; $boundary="---------FGf4Fh3fdjGQ148fdh"; $content="--$boundary\r\n"; $content.="Content-Disposition: form-data; name=\"method\"\r\n"; $content.="\r\n"; $content.="post\r\n"; $content.="--$boundary\r\n"; $content.="Content-Disposition: form-data; name=\"key\"\r\n"; $content.="\r\n"; $content.="$apikey\r\n"; $content.="--$boundary\r\n"; $content.="Content-Disposition: form-data; name=\"phrase\"\r\n"; $content.="\r\n"; $content.="$is_phrase\r\n"; $content.="--$boundary\r\n"; $content.="Content-Disposition: form-data; name=\"regsense\"\r\n"; $content.="\r\n"; $content.="$is_regsense\r\n"; $content.="--$boundary\r\n"; $content.="Content-Disposition: form-data; name=\"numeric\"\r\n"; $content.="\r\n"; $content.="$is_numeric\r\n"; $content.="--$boundary\r\n"; $content.="Content-Disposition: form-data; name=\"min_len\"\r\n"; $content.="\r\n"; $content.="$min_len\r\n"; $content.="--$boundary\r\n"; $content.="Content-Disposition: form-data; name=\"max_len\"\r\n"; $content.="\r\n"; $content.="$max_len\r\n"; $content.="--$boundary\r\n"; $content.="Content-Disposition: form-data; name=\"is_russian\"\r\n"; $content.="\r\n"; $content.="$is_russian\r\n"; $content.="--$boundary\r\n"; $content.="Content-Disposition: form-data; name=\"file\"; filename=\"capcha.$ext\"\r\n"; $content.="Content-Type: $conttype\r\n"; $content.="\r\n"; $content.=$body."\r\n"; $content.="--$boundary--"; $poststr="POST http://$sendhost/in.php HTTP/1.0\r\n"; $poststr.="Content-Type: multipart/form-data; boundary=$boundary\r\n"; $poststr.="Host: $sendhost\r\n"; $poststr.="Content-Length: ".strlen($content)."\r\n\r\n"; $poststr.=$content; $fp=fsockopen($sendhost,80,$errno,$errstr,30); if ($fp!=false) { fputs($fp,$poststr); $resp=""; while (!feof($fp)) $resp.=fgets($fp,1024); fclose($fp); $result=substr($resp,strpos($resp,"\r\n\r\n")+4); } else { if ($is_verbose) echo "<b>could not connect to anti-captcha</b>"; if ($is_verbose) echo "<b>socket error: $errno ( $errstr )</b>"; return false; } if (strpos($result, "ERROR")!==false or strpos($result, "<HTML>")!==false) { if ($is_verbose) echo "<b>server returned error: $result</b>"; return false; } else { $ex = explode("|", $result); $captcha_id = $ex[1]; if ($is_verbose) echo "<b>$captcha_id</b>"; } } $text=recognize("captcha.png"," ",true,"antigate.com"); ?>
$is_phrase = 0, // $is_regsense = 1, // ? $is_numeric = 0, // ? $min_len = 4, // $max_len = 4, // $is_russian = 1 //
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait import time driver = webdriver.Firefox() # () add_driver = webdriver.Firefox() # driver.get("https://by.e-konsulat.gov.pl/Uslugi/RejestracjaTerminu.aspx?IDUSLUGI=8&IDPlacowki=94") # captcha_url = driver.find_element_by_id('c_uslugi_rejestracjaterminu_ctl00_cp_botdetectcaptcha_CaptchaImage').get_attribute('src') # id , add_driver.get(captcha_url) # add_driver.set_window_size(50,200) # , , add_driver.get_screenshot_as_file('captcha.png') # , test1.ru, .. , add_driver.get(http://test1.ru) # , captcha_id = add_driver.find_element_by_xpatch('//b') # , b, , id count = false while (count == false) add_driver.get('http://antigate.com/res.php?key= &action=get&id=" + captcha_id) captcha_complete = add_driver.find_element_by_xpatch('//pre').text # ( pre) if (captcha_complete.find('ERROR') >= 0) #, time.sleep(5) # 5 else count = true # # captcha_complete, driver.find_element_by_id('ctl00_cp_BotDetectCaptchaCodeTextBox').send_keys(captcha_complete) # driver.find_element_by_id('ctl00_cp_btnDalej').click() # result = driver.find_element_by_id('ctl00_cp_lblBrakTerminow').text if (result.find('') >= 0) print(' ') else print(' ')
Source: https://habr.com/ru/post/190870/
All Articles