{"id":319367,"date":"2021-03-11T09:00:21","date_gmt":"2021-03-11T09:00:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=319367"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=319367","title":{"rendered":"\u0412\u0437\u043b\u043e\u043c reCAPTCHA v2"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0430\u0437\u043e\u0439\u043b\u0438\u0432\u0430\u044f \u0438\u0433\u0440\u0430 &#8212; \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f google. \u0415\u0441\u043b\u0438, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0435\u0441\u044c \u0441\u0431\u043e\u0440\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u043c \u0432\u0430\u043c, \u0438 \u043d\u0435 \u0441\u0443\u043c\u0435\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u0435\u0433\u0440\u0430\u0434\u044b, \u0441\u043e\u0432\u0435\u0442\u044b \u043e\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0430\u043c \u043f\u043e\u043c\u043e\u0433\u0443\u0442. \u041e\u043f\u0438\u0448\u0443 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u0442\u0438\u043f\u043e\u043c 4&#215;4, \u0445\u0443\u0436\u0435 \u0441 3&#215;3. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 YOLO, &#171;\u0437\u043e\u043b\u043e\u0442\u0430\u044f \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0430&#187; \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438\/\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0434\u0445\u043e\u0434 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u043e\u0432. \u0412 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c &#171;\u0430\u043d\u0441\u0430\u043c\u0431\u043b\u044c&#187; \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439, \u043a \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438, \u044d\u0442\u043e \u043f\u043e\u0432\u044b\u0441\u0438\u0442 \u043e\u0431\u0449\u0443\u044e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e. \u0422\u0430\u043a\u0436\u0435 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u0434\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u0435\u043c A2C\/DQN \u0438\u043b\u0438 \u043b\u044e\u0431\u0443\u044e \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u044b, \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e-\u0441\u043e\u0441\u0442\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0435\u0442\u0438.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/h4>\n<ol>\n<li>\n<p>\u041f\u043e\u0438\u0441\u043a \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043d\u043e\u043f\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u0438\u0442\u0430\u0446\u0438\u044f \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u043c\u044b\u0448\u0438 \u043a \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c \u043a\u043d\u043e\u043f\u043a\u0438 &#171;\u042f \u043d\u0435 \u0440\u043e\u0431\u043e\u0442&#187;<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u0438\u0442\u0430\u0446\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438 &#171;\u042f \u043d\u0435 \u0440\u043e\u0431\u043e\u0442&#187;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 ( \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 google, \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u043e\u0439 )<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 ( \u0438\u0437 html )<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u044f\u0447\u0435\u0435\u043a ( \u0438\u0437 html )<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u0410\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u044f\u0447\u0435\u0435\u043a \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0436\u0430\u0442\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\/\u0434\u0430\u043b\u0435\u0435\/\u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c<\/p>\n<\/li>\n<\/ol>\n<p>\u0415\u0441\u043b\u0438 reCaptcha \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0441 4 \u043f\u043e 10.<\/p>\n<h4>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0432 Python<\/h4>\n<ul>\n<li>\n<p>pynput<\/p>\n<\/li>\n<li>\n<p>selenium<\/p>\n<\/li>\n<li>\n<p>numpy<\/p>\n<\/li>\n<li>\n<p>tensorflow<\/p>\n<\/li>\n<li>\n<p>opencv<\/p>\n<\/li>\n<li>\n<p>scipy<\/p>\n<\/li>\n<li>\n<p>beautiful soup, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u043e\u0434\u043d\u0438\u043c selenium<\/p>\n<\/li>\n<\/ul>\n<p><em>\u041a\u043e\u0434 \u043d\u0430\u0439\u0434\u0435\u043d \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u043c\u043e\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e \u0442\u043e \u0432\u0438\u0434\u0435\u043b \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0441\u0435\u0442\u0438, \u0436\u0438\u0432\u0443 \u043d\u0435 \u0432 \u0432\u0430\u043a\u0443\u0443\u043c\u0435<\/em><\/p>\n<pre><code class=\"python\">from selenium import webdriver from selenium.webdriver.firefox.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.by import By from pynput.mouse import Button, Controller import scipy.interpolate as si import numpy as np import cv2 import time import random import os import io import base64  # \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 B-\u0441\u043f\u043b\u0430\u0439\u043d\u0430 \u0434\u043b\u044f \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u0438 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0439 \u043c\u044b\u0448\u0438 def human_like_mouse_move(action, start_element):     points = [[6, 2], [3, 2],[0, 0], [0, 2]];     points = np.array(points)     x = points[:,0]     y = points[:,1]     t = range(len(points))     ipl_t = np.linspace(0.0, len(points) - 1, 100)     x_tup = si.splrep(t, x, k=1)     y_tup = si.splrep(t, y, k=1)     x_list = list(x_tup)     xl = x.tolist()     x_list[1] = xl + [0.0, 0.0, 0.0, 0.0]     y_list = list(y_tup)     yl = y.tolist()     y_list[1] = yl + [0.0, 0.0, 0.0, 0.0]     x_i = si.splev(ipl_t, x_list)     y_i = si.splev(ipl_t, y_list)     startElement = start_element     action.move_to_element(startElement);     action.perform();     c = 5     i = 0     for mouse_x, mouse_y in zip(x_i, y_i):         action.move_by_offset(mouse_x,mouse_y);         action.perform();         print(\"Move mouse to, %s ,%s\" % (mouse_x, mouse_y))            i += 1             if i == c:             break;  # \"\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\" selenium def my_proxy(PROXY_HOST,PROXY_PORT):     fp = webdriver.FirefoxProfile()     fp.set_preference(\"network.proxy.type\", 1)     fp.set_preference(\"network.proxy.socks\",PROXY_HOST)     fp.set_preference(\"network.proxy.socks_port\",int(PROXY_PORT))     fp.update_preferences()     options = Options()     options.headless = True # \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e     return webdriver.Firefox(executable_path=\"geckodriver\/geckodriver\", options=options, firefox_profile=fp)  # \u0441 tor \u043f\u0440\u043e\u043a\u0441\u0438, reCaptcha \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0447\u043d\u043e\u0439,  # \u0445\u043e\u0440\u043e\u0448\u043e \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 proxy = my_proxy(\"127.0.0.1\", 9050) proxy.get(\"https:\/\/www.google.com\/search?q=apple\")<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043c\u043d\u043e\u0433\u0438\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c, \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f reCaptcha.<\/p>\n<pre><code class=\"python\"># reCaptcha \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0432 iframe's  # \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 iframe \u21161 proxy.switch_to.frame(proxy.find_elements_by_tag_name(\"iframe\")[0])  # \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043a\u043d\u043e\u043f\u043a\u0443 \"\u042f \u043d\u0435 \u0440\u043e\u0431\u043e\u0442\" check_box = WebDriverWait(proxy, 10).until(EC.element_to_be_clickable((By.ID ,\"recaptcha-anchor\"))) time.sleep(2) # \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \"\u042f \u043d\u0435 \u0440\u043e\u0431\u043e\u0442 action =  ActionChains(proxy); human_like_mouse_move(action, check_box) check_box.click() time.sleep(2)<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/410\/ef4\/0c2\/410ef40c2cd8c6f0575e21595f382db7.png\" width=\"451\" height=\"435\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438: \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0438\u0441\u043a\u0430, \u0442\u0438\u043f reCaptcha.<\/p>\n<pre><code class=\"python\"># \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 iframe \u21162 proxy.switch_to.default_content() iframes = proxy.find_elements_by_tag_name(\"iframe\") proxy.switch_to.frame(iframes[2]) html = proxy.page_source # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0438\u043f reCaptcha try:       img_rc = proxy.find_elements_by_xpath('\/\/img[@class=\"rc-image-tile-33\"]')[0]       t_type = 3 except IndexError:       img_rc = proxy.find_elements_by_xpath('\/\/img[@class=\"rc-image-tile-44\"]')[0]       t_type = 4  # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 try:       required_class = proxy.find_elements_by_xpath('\/\/div[@class=\"rc-imageselect-desc-no-canonical\"]\/strong')[0].text except IndexError:       required_class = proxy.find_elements_by_xpath('\/\/div[@class=\"rc-imageselect-desc\"]\/strong')[0].text time.sleep(2)<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/76d\/3e6\/c42\/76d3e6c42e6da120c2644d165fc4b437.png\" width=\"501\" height=\"633\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043d\u0435 \u0441\u0430\u043c\u044b\u043c &#171;\u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c&#187;. \u0412\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u0434 javascript, \u0447\u0442\u043e \u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c XMLHttpRequest, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0432 canvas, \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 python \u0441\u0442\u0440\u043e\u043a\u043e\u0439 base64. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f base64, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0432 numpy array. \u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/449236\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/post\/449236\/<\/a><\/p>\n<pre><code class=\"python\">answ = proxy.execute_script('''                  var img = new Image();                 var cnv = document.createElement('canvas');                 cnv.id = 'tutorial';                     img.onload = function(){                       cnv.height = img.height;                       cnv.width = img.width;                       console.log(cnv.width, cnv.height, img.width, img.height);                       cnv.getContext('2d').drawImage(img, 0, 0);                     }                         var request = new XMLHttpRequest();                         request.open('GET', arguments[0].src);                         request.responseType = 'blob';                         request.onload = function() {                             var reader = new FileReader();                             reader.readAsDataURL(request.response);                             reader.onload =  function(e){                                 img.src = e.target.result;                             };                         };                         request.send();                 var child = document.body.appendChild(cnv);                 ''', img_rc) time.sleep(4) answ = proxy.execute_script('''                  cnv = document.getElementById('tutorial');                 return cnv.toDataURL('image\/jpeg').substring(22);                 ''')  nparr = np.asarray(bytearray(io.BytesIO(base64.b64decode(answ)).read()), dtype=np.uint8) img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR)<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/08d\/1c2\/c6b\/08d1c2c6b6299e8a4e55e5539af531fc.png\" width=\"453\" height=\"485\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441: &#171;\u0432 \u043a\u0430\u043a\u043e\u043c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442&#187;. \u041d\u0430 \u044d\u0442\u043e\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0435 \u043d\u0435 \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0440\u0430\u0437 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 YOLO \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0434\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<pre><code class=\"python\">def draw_boxes(image, boxes, scores, labels, classes, detection_size, search_class):     \"\"\"     :param boxes, shape of  [num, 4]     :param scores, shape of [num, ]     :param labels, shape of [num, ]     :param image,     :param classes, the return list from the function `read_coco_names`     \"\"\"     new = np.ones(shape=image.shape, dtype=np.float32)     ans = []     if boxes is None:          return ans, image, new     for i in range(len(labels)): # for each bounding box, do:         bbox, score, label = boxes[i], scores[i], classes[labels[i]]         bbox_text = \"%s %.2f\" %(label, score)         # convert_to_original_size         detection_size, original_size = np.array(detection_size), np.array(image.shape[1])         ratio = float(original_size) \/ float(detection_size)         bbox = list((bbox.reshape(2,2) * ratio).reshape(-1))         coord = [abs(int(x)) for x in bbox]         # \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u043b\u043e\u0445\u043e\u0439 \u043a\u043e\u0434         o0 = coord[0]         o1 = coord[1]         o2 = coord[2]         o3 = coord[3]         # \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0441\u043a\u0443 \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432         if search_class == label.split('\\n')[0]:              new[o1:o3, o0:o2, :] = 2              ans.append(classes[labels[i]])     return ans, image, new    # \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 def imcr(i, col, activation_threshold = 1):     answ = []     im_w, im_h, im_c = i.shape     w, h = im_w\/\/col, im_h\/\/col     sZero = i[0:w, 0:h,:].size     num = 0     for wi in range(0, col): \t\t    for hi in range(0, col):                         num += 1                         P_R = (np.sum(i[wi*w:(wi+1)*w, hi*h:(hi+1)*h, :]) \/ sZero) * 100                         P_R = P_R - 100                         if activation_threshold &lt; int(P_R):                               answ.append(num)                         else:                               pass     return answ    def ocr(img_np, required_class, t_type):     # img_np -&gt; YOLO -&gt; B,C      # \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u0438\u044f     boxes, scores, labels = cpu_nms(B, C, len(classes), max_boxes=1000, score_thresh=0.4, iou_thresh=0.5)     # \u0432\u0441\u0442\u0440\u043e\u0438\u043b \u0441\u0432\u043e\u0439 \u043f\u043b\u043e\u0445\u043e\u0439 \u043a\u043e\u0434 \u0432 \u0447\u0443\u0436\u043e\u0439 \u043a\u043e\u0434 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445     result, img, z_image = draw_boxes(img_np, boxes, scores, labels, classes, yolo_image_shape, required_class)     # \u043d\u0430\u0448\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f     answ = imcr(np.array(z_image), t_type)  <\/code><\/pre>\n<p>\u041d\u0430\u0448\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, <strong>imcr(<\/strong>image_array,  type_captcha, activation_threshold<strong>)  &#8212; <\/strong>\u043f\u043e\u043b\u0443\u0447\u0430\u044f \u043c\u0430\u0441\u043a\u0443 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0435 \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e<\/p>\n<ul>\n<li>\n<p><strong>\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<br \/><\/strong>image_array &#8212; \u043c\u0430\u0441\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<br \/>type_captcha &#8212; \u0442\u0438\u043f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u043f\u0440\u0438\u043c\u0435\u0440 4 (4&#215;4)<br \/>activation_threshold &#8212; \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1%<\/p>\n<\/li>\n<li>\n<p><strong>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442:<br \/><\/strong>\u043d\u043e\u043c\u0435\u0440\u0430 \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u044f\u0447\u0435\u0435\u043a \u0432 \u0441\u043f\u0438\u0441\u043a\u0435<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043d\u0443\u0436\u043d\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438, \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u043c.<\/p>\n<pre><code class=\"python\">answ_ocr = ocr(img_np, required_class, t_type) ids = proxy.find_elements_by_xpath('\/\/td[@class=\"rc-imageselect-tile\"]') for i in answ_ocr:       ids[i].click()  # \u043f\u043e\u0438\u0441\u043a \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f   confirm_btn = WebDriverWait(proxy, 4).until(EC.element_to_be_clickable((By.XPATH ,'\/\/button[@id=\"recaptcha-verify-button\"]'))) #\u041d\u0430\u0445\u043e\u0436\u0443 \u043a\u043d\u043e\u043f\u043a\u0443 action =  ActionChains(proxy); human_like_mouse_move(action, confirm_btn) # \u0434\u0432\u0438\u0433\u0430\u0442\u044c \u043a\u0443\u0440\u0441\u043e\u0440 \u043a \u043a\u043d\u043e\u043f\u043a\u0435   confirm_btn.click() # \u043d\u0430\u0436\u0430\u0442\u044c<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043d\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e, \u0430 \u0441\u043e\u0432\u0435\u0442\u044b \u0441 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043a\u043e\u0434\u0430. \u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c\u0438, \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c 93% \u0438 \u0432\u044b\u0448\u0435. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440, \u0432\u0430\u0448\u0430 \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u0430 (YOLO, RCNN, SSD). \u0422\u0430\u043a\u0436\u0435, \u043e\u0434\u043d\u043e \u0438\u0437 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u043e\u0431\u0445\u043e\u0434\u0430 google captcha, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 &#171;\u0447\u0438\u0441\u0442\u044b\u0445 proxy&#187;. \u0423 \u043c\u0435\u043d\u044f \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043c\u044b\u0441\u043b\u0438 \u0432 \u0442\u0435\u043a\u0441\u0442, \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u0430,  \u0438 \u043c\u043e\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0435.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/546464\/\"> https:\/\/habr.com\/ru\/post\/546464\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0430\u0437\u043e\u0439\u043b\u0438\u0432\u0430\u044f \u0438\u0433\u0440\u0430 &#8212; \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f google. \u0415\u0441\u043b\u0438, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0435\u0441\u044c \u0441\u0431\u043e\u0440\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u043c \u0432\u0430\u043c, \u0438 \u043d\u0435 \u0441\u0443\u043c\u0435\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u0435\u0433\u0440\u0430\u0434\u044b, \u0441\u043e\u0432\u0435\u0442\u044b \u043e\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0430\u043c \u043f\u043e\u043c\u043e\u0433\u0443\u0442. \u041e\u043f\u0438\u0448\u0443 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u0442\u0438\u043f\u043e\u043c 4&#215;4, \u0445\u0443\u0436\u0435 \u0441 3&#215;3. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 YOLO, &#171;\u0437\u043e\u043b\u043e\u0442\u0430\u044f \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0430&#187; \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438\/\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0434\u0445\u043e\u0434 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u043e\u0432. \u0412 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c &#171;\u0430\u043d\u0441\u0430\u043c\u0431\u043b\u044c&#187; \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439, \u043a \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438, \u044d\u0442\u043e \u043f\u043e\u0432\u044b\u0441\u0438\u0442 \u043e\u0431\u0449\u0443\u044e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e. \u0422\u0430\u043a\u0436\u0435 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u0434\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u0435\u043c A2C\/DQN \u0438\u043b\u0438 \u043b\u044e\u0431\u0443\u044e \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u044b, \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e-\u0441\u043e\u0441\u0442\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0435\u0442\u0438.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/h4>\n<ol>\n<li>\n<p>\u041f\u043e\u0438\u0441\u043a \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043d\u043e\u043f\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u0438\u0442\u0430\u0446\u0438\u044f \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u043c\u044b\u0448\u0438 \u043a \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c \u043a\u043d\u043e\u043f\u043a\u0438 &#171;\u042f \u043d\u0435 \u0440\u043e\u0431\u043e\u0442&#187;<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u0438\u0442\u0430\u0446\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438 &#171;\u042f \u043d\u0435 \u0440\u043e\u0431\u043e\u0442&#187;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 ( \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 google, \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u043e\u0439 )<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 ( \u0438\u0437 html )<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u044f\u0447\u0435\u0435\u043a ( \u0438\u0437 html )<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u0410\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u044f\u0447\u0435\u0435\u043a \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0436\u0430\u0442\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\/\u0434\u0430\u043b\u0435\u0435\/\u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c<\/p>\n<\/li>\n<\/ol>\n<p>\u0415\u0441\u043b\u0438 reCaptcha \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0441 4 \u043f\u043e 10.<\/p>\n<h4>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0432 Python<\/h4>\n<ul>\n<li>\n<p>pynput<\/p>\n<\/li>\n<li>\n<p>selenium<\/p>\n<\/li>\n<li>\n<p>numpy<\/p>\n<\/li>\n<li>\n<p>tensorflow<\/p>\n<\/li>\n<li>\n<p>opencv<\/p>\n<\/li>\n<li>\n<p>scipy<\/p>\n<\/li>\n<li>\n<p>beautiful soup, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u043e\u0434\u043d\u0438\u043c selenium<\/p>\n<\/li>\n<\/ul>\n<p><em>\u041a\u043e\u0434 \u043d\u0430\u0439\u0434\u0435\u043d \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u043c\u043e\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e \u0442\u043e \u0432\u0438\u0434\u0435\u043b \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0441\u0435\u0442\u0438, \u0436\u0438\u0432\u0443 \u043d\u0435 \u0432 \u0432\u0430\u043a\u0443\u0443\u043c\u0435<\/em><\/p>\n<pre><code class=\"python\">from selenium import webdriver from selenium.webdriver.firefox.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.by import By from pynput.mouse import Button, Controller import scipy.interpolate as si import numpy as np import cv2 import time import random import os import io import base64  # \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 B-\u0441\u043f\u043b\u0430\u0439\u043d\u0430 \u0434\u043b\u044f \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u0438 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0439 \u043c\u044b\u0448\u0438 def human_like_mouse_move(action, start_element):     points = [[6, 2], [3, 2],[0, 0], [0, 2]];     points = np.array(points)     x = points[:,0]     y = points[:,1]     t = range(len(points))     ipl_t = np.linspace(0.0, len(points) - 1, 100)     x_tup = si.splrep(t, x, k=1)     y_tup = si.splrep(t, y, k=1)     x_list = list(x_tup)     xl = x.tolist()     x_list[1] = xl + [0.0, 0.0, 0.0, 0.0]     y_list = list(y_tup)     yl = y.tolist()     y_list[1] = yl + [0.0, 0.0, 0.0, 0.0]     x_i = si.splev(ipl_t, x_list)     y_i = si.splev(ipl_t, y_list)     startElement = start_element     action.move_to_element(startElement);     action.perform();     c = 5     i = 0     for mouse_x, mouse_y in zip(x_i, y_i):         action.move_by_offset(mouse_x,mouse_y);         action.perform();         print(\"Move mouse to, %s ,%s\" % (mouse_x, mouse_y))            i += 1             if i == c:             break;  # \"\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\" selenium def my_proxy(PROXY_HOST,PROXY_PORT):     fp = webdriver.FirefoxProfile()     fp.set_preference(\"network.proxy.type\", 1)     fp.set_preference(\"network.proxy.socks\",PROXY_HOST)     fp.set_preference(\"network.proxy.socks_port\",int(PROXY_PORT))     fp.update_preferences()     options = Options()     options.headless = True # \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e     return webdriver.Firefox(executable_path=\"geckodriver\/geckodriver\", options=options, firefox_profile=fp)  # \u0441 tor \u043f\u0440\u043e\u043a\u0441\u0438, reCaptcha \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0447\u043d\u043e\u0439,  # \u0445\u043e\u0440\u043e\u0448\u043e \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 proxy = my_proxy(\"127.0.0.1\", 9050) proxy.get(\"https:\/\/www.google.com\/search?q=apple\")<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043c\u043d\u043e\u0433\u0438\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c, \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f reCaptcha.<\/p>\n<pre><code class=\"python\"># reCaptcha \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0432 iframe's  # \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 iframe \u21161 proxy.switch_to.frame(proxy.find_elements_by_tag_name(\"iframe\")[0])  # \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043a\u043d\u043e\u043f\u043a\u0443 \"\u042f \u043d\u0435 \u0440\u043e\u0431\u043e\u0442\" check_box = WebDriverWait(proxy, 10).until(EC.element_to_be_clickable((By.ID ,\"recaptcha-anchor\"))) time.sleep(2) # \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \"\u042f \u043d\u0435 \u0440\u043e\u0431\u043e\u0442 action =  ActionChains(proxy); human_like_mouse_move(action, check_box) check_box.click() time.sleep(2)<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438: \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0438\u0441\u043a\u0430, \u0442\u0438\u043f reCaptcha.<\/p>\n<pre><code class=\"python\"># \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 iframe \u21162 proxy.switch_to.default_content() iframes = proxy.find_elements_by_tag_name(\"iframe\") proxy.switch_to.frame(iframes[2]) html = proxy.page_source # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0438\u043f reCaptcha try:       img_rc = proxy.find_elements_by_xpath('\/\/img[@class=\"rc-image-tile-33\"]')[0]       t_type = 3 except IndexError:       img_rc = proxy.find_elements_by_xpath('\/\/img[@class=\"rc-image-tile-44\"]')[0]       t_type = 4  # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 try:       required_class = proxy.find_elements_by_xpath('\/\/div[@class=\"rc-imageselect-desc-no-canonical\"]\/strong')[0].text except IndexError:       required_class = proxy.find_elements_by_xpath('\/\/div[@class=\"rc-imageselect-desc\"]\/strong')[0].text time.sleep(2)<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043d\u0435 \u0441\u0430\u043c\u044b\u043c &#171;\u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c&#187;. \u0412\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u0434 javascript, \u0447\u0442\u043e \u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c XMLHttpRequest, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0432 canvas, \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 python \u0441\u0442\u0440\u043e\u043a\u043e\u0439 base64. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f base64, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0432 numpy array. \u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/449236\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/post\/449236\/<\/a><\/p>\n<pre><code class=\"python\">answ = proxy.execute_script('''                  var img = new Image();                 var cnv = document.createElement('canvas');                 cnv.id = 'tutorial';                     img.onload = function(){                       cnv.height = img.height;                       cnv.width = img.width;                       console.log(cnv.width, cnv.height, img.width, img.height);                       cnv.getContext('2d').drawImage(img, 0, 0);                     }                         var request = new XMLHttpRequest();                         request.open('GET', arguments[0].src);                         request.responseType = 'blob';                         request.onload = function() {                             var reader = new FileReader();                             reader.readAsDataURL(request.response);                             reader.onload =  function(e){                                 img.src = e.target.result;                             };                         };                         request.send();                 var child = document.body.appendChild(cnv);                 ''', img_rc) time.sleep(4) answ = proxy.execute_script('''                  cnv = document.getElementById('tutorial');                 return cnv.toDataURL('image\/jpeg').substring(22);                 ''')  nparr = np.asarray(bytearray(io.BytesIO(base64.b64decode(answ)).read()), dtype=np.uint8) img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR)<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441: &#171;\u0432 \u043a\u0430\u043a\u043e\u043c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442&#187;. \u041d\u0430 \u044d\u0442\u043e\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0435 \u043d\u0435 \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0440\u0430\u0437 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 YOLO \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0434\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<pre><code class=\"python\">def draw_boxes(image, boxes, scores, labels, classes, detection_size, search_class):     \"\"\"     :param boxes, shape of  [num, 4]     :param scores, shape of [num, ]     :param labels, shape of [num, ]     :param image,     :param classes, the return list from the function `read_coco_names`     \"\"\"     new = np.ones(shape=image.shape, dtype=np.float32)     ans = []     if boxes is None:          return ans, image, new     for i in range(len(labels)): # for each bounding box, do:         bbox, score, label = boxes[i], scores[i], classes[labels[i]]         bbox_text = \"%s %.2f\" %(label, score)         # convert_to_original_size         detection_size, original_size = np.array(detection_size), np.array(image.shape[1])         ratio = float(original_size) \/ float(detection_size)         bbox = list((bbox.reshape(2,2) * ratio).reshape(-1))         coord = [abs(int(x)) for x in bbox]         # \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u043b\u043e\u0445\u043e\u0439 \u043a\u043e\u0434         o0 = coord[0]         o1 = coord[1]         o2 = coord[2]         o3 = coord[3]         # \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0441\u043a\u0443 \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432         if search_class == label.split('\\n')[0]:              new[o1:o3, o0:o2, :] = 2              ans.append(classes[labels[i]])     return ans, image, new    # \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 def imcr(i, col, activation_threshold = 1):     answ = []     im_w, im_h, im_c = i.shape     w, h = im_w\/\/col, im_h\/\/col     sZero = i[0:w, 0:h,:].size     num = 0     for wi in range(0, col): \t\t    for hi in range(0, col):                         num += 1                         P_R = (np.sum(i[wi*w:(wi+1)*w, hi*h:(hi+1)*h, :]) \/ sZero) * 100                         P_R = P_R - 100                         if activation_threshold &lt; int(P_R):                               answ.append(num)                         else:                               pass     return answ    def ocr(img_np, required_class, t_type):     # img_np -&gt; YOLO -&gt; B,C      # \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u0438\u044f     boxes, scores, labels = cpu_nms(B, C, len(classes), max_boxes=1000, score_thresh=0.4, iou_thresh=0.5)     # \u0432\u0441\u0442\u0440\u043e\u0438\u043b \u0441\u0432\u043e\u0439 \u043f\u043b\u043e\u0445\u043e\u0439 \u043a\u043e\u0434 \u0432 \u0447\u0443\u0436\u043e\u0439 \u043a\u043e\u0434 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445     result, img, z_image = draw_boxes(img_np, boxes, scores, labels, classes, yolo_image_shape, required_class)     # \u043d\u0430\u0448\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f     answ = imcr(np.array(z_image), t_type)  <\/code><\/pre>\n<p>\u041d\u0430\u0448\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, <strong>imcr(<\/strong>image_array,  type_captcha, activation_threshold<strong>)  &#8212; <\/strong>\u043f\u043e\u043b\u0443\u0447\u0430\u044f \u043c\u0430\u0441\u043a\u0443 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0435 \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e<\/p>\n<ul>\n<li>\n<p><strong>\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<br \/><\/strong>image_array &#8212; \u043c\u0430\u0441\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<br \/>type_captcha &#8212; \u0442\u0438\u043f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u043f\u0440\u0438\u043c\u0435\u0440 4 (4&#215;4)<br \/>activation_threshold &#8212; \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1%<\/p>\n<\/li>\n<li>\n<p><strong>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442:<br \/><\/strong>\u043d\u043e\u043c\u0435\u0440\u0430 \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u044f\u0447\u0435\u0435\u043a \u0432 \u0441\u043f\u0438\u0441\u043a\u0435<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043d\u0443\u0436\u043d\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438, \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u043c.<\/p>\n<pre><code class=\"python\">answ_ocr = ocr(img_np, required_class, t_type) ids = proxy.find_elements_by_xpath('\/\/td[@class=\"rc-imageselect-tile\"]') for i in answ_ocr:       ids[i].click()  # \u043f\u043e\u0438\u0441\u043a \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f   confirm_btn = WebDriverWait(proxy, 4).until(EC.element_to_be_clickable((By.XPATH ,'\/\/button[@id=\"recaptcha-verify-button\"]'))) #\u041d\u0430\u0445\u043e\u0436\u0443 \u043a\u043d\u043e\u043f\u043a\u0443<\/code><\/pre>\n<p><\/strong><\/p>\n<\/li>\n<\/ul>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-319367","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=319367"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319367\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=319367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=319367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=319367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}