-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
134 lines (96 loc) · 4.44 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from time import sleep
from random import uniform
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from clarifai.client import ClarifaiApi
from image_helper import ImageHelper
import inflect
import json
def check_exists_by_name(web_driver, classname):
try:
web_driver.find_element_by_class_name(classname)
except NoSuchElementException:
return False
return True
def check_if_is_solved(web_driver):
web_driver.switch_to.default_content()
web_driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@src,'enquete')]"))
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@title,'widget')]"))
try:
check_box = driver.find_element_by_id("recaptcha-anchor")
has_checked = check_box.get_attribute('aria-checked')
if has_checked == 'true':
return True
else:
return False
except NoSuchElementException:
return False
def wait_between(a, b):
rand = uniform(a, b)
sleep(rand)
def vote(web_driver):
web_driver.switch_to.default_content()
web_driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@src,'enquete')]"))
btn_vote = driver.find_element_by_id("votar")
btn_vote.click()
p = inflect.engine()
config = json.load(open('config.json'))['data']
url = config['target_url']
clarifai_client_language = config['clarifai_settings']['language']
clarifai_client_settings = config['clarifai_settings']['applications'][0]
while True:
profile = webdriver.FirefoxProfile()
profile.set_preference("intl.accept_languages", "en")
driver = webdriver.Firefox(firefox_profile=profile)
driver.get(url)
driver.switch_to.default_content()
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@src,'enquete')]"))
option = driver.find_element_by_xpath("//input[contains(@value,'66')]")
option.click()
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@title,'widget')]"))
wait_between(0.2, 0.5)
checkbox = driver.find_element_by_xpath("//*[@id='recaptcha-anchor']")
checkbox.click()
wait_between(1.0, 2.0)
if check_if_is_solved(driver):
print('\n\r reCaptcha is solved!')
else:
driver.switch_to.default_content()
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@src,'enquete')]"))
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@title,'challenge')]"))
if check_exists_by_name(driver, "rc-imageselect-desc-no-canonical"):
text_tag = driver.find_element_by_class_name("rc-imageselect-desc-no-canonical")
sentence_tag = text_tag.find_element_by_tag_name("strong")
sentence_text = sentence_tag.text
sentence = sentence_text.split()
image_tag = driver.find_element_by_xpath("//img[contains(@class,'rc-image')]")
image_url = image_tag.get_attribute('src')
image_aux = ImageHelper(image_url)
image_aux.generate_images()
api = ClarifaiApi(app_id=clarifai_client_settings['id'],
app_secret=clarifai_client_settings['secret'],
language=clarifai_client_language)
tiles = driver.find_element_by_id("rc-imageselect-target")
table = tiles.find_element_by_tag_name("table")
tds = table.find_elements_by_tag_name("td")
if len(tds) == 9: # prevent error when recaptcha put more than 9 pics
for idx, td in enumerate(tds):
response = api.tag_images(image_aux.get_image(idx+1))
results = response['results'][0]['result']['tag']['classes']
plurals = []
for result in results:
plurals.append(p.plural(result))
results.extend(plurals)
for word in sentence:
if word in results:
td.find_element_by_class_name("rc-image-tile-target").click()
break
driver.find_element_by_id("recaptcha-verify-button").click()
wait_between(1.0, 1.5)
if check_if_is_solved(driver):
print('\n\r reCaptcha is solved! :) ')
vote(driver)
else:
print('\n\r Maybe in next time :/ ')
wait_between(1.0, 1.5)
driver.close()