-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc_img.py
59 lines (38 loc) · 1.46 KB
/
proc_img.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
# -*- coding: utf-8 -*-
"""
Creaed on Fri Jul 8 21:48:01 2022
@author: Acer
"""
""" Obtengo texto de la imagen con vision de G-cloud"""
from google.cloud import vision
import io
from CAPTCHA import *
import re
# implemento un modelo pre entrenado de vision con G-cloud
client = vision.ImageAnnotatorClient()
with io.open('C:/Users/Acer/Desktop/data engineer/CAPTCHA.png', 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
print('Texts:')
for text in texts:
print('\n"{}"'.format(text.description))
vertices = (['({},{})'.format(vertex.x, vertex.y)
for vertex in text.bounding_poly.vertices])
print('limites: {}'.format(','.join(vertices)))
if response.error.message:
raise Exception(
'{}\nFor more info on error messages, check: '
'https://cloud.google.com/apis/design/errors'.format(
response.error.message))
myword = texts[0].description
patron = '[\W+]'
regex = re.compile(patron)
resultado = regex.sub('', myword)
# Tomo caracteres y los agrego a la utomatizacion
WebDriverWait(driver, 2)\
.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input'))).click()
WebDriverWait(driver, 2)\
.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input'))).send_keys(resultado)
print('\n CAPTCHA a utilizar: "{}"'.format(resultado))