-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
65 lines (44 loc) · 1.68 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import cv2
import numpy as np
from matplotlib import pyplot as plt
import pyautogui
import time
import pyscreenshot as ImageGrab
# Demo https://www.google.com/recaptcha/api2/demo
time.sleep(1)
coords = []
print('-> Locating coordinates of reCAPTCHA...')
pic = pyautogui.screenshot() # taking screenshot
pic.save('screenshot.jpg') # saving screenshot
img_rgb = cv2.imread('screenshot.jpg')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) ###beginning template matching###
template = cv2.imread('find1.jpg', 0) #
w, h = template.shape[::-1] #
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
coords.append(pt[0]) # storing upper left coordinates of reCAPTCHA box
coords.append(pt[1])
if len(coords) != 0:
print('-> Location found reCAPTCHA at :', coords)
reCAPTCHA_box_x_bias = 10
reCAPTCHA_box_y_bias = 20
coords[0] = coords[0] + reCAPTCHA_box_x_bias
coords[1] = coords[1] + reCAPTCHA_box_y_bias
print('-> Moving cursor to (1, 1)')
pyautogui.moveTo(1, 1, duration=0)
print('-> Moving cursor towards reCAPTCHA')
pyautogui.moveTo(coords[0], coords[1], duration=0.12)
print('-> Performing click action on reCAPTCHA')
pyautogui.click()
time.sleep(4)
Submit_button_x_bias = 0
Submit_button_y_bias = 75
coords[0] = coords[0] + Submit_button_x_bias
coords[1] = coords[1] + Submit_button_y_bias
pyautogui.moveTo(coords[0], coords[1], duration=0.14)
print('-> Performing click action on Submit')
pyautogui.click()
else:
print('-> reCAPTCHA box not found!')