reCaptcha said that captcha is wrong (but it's not wrong!) - python

I'm using Raspberry Pi with Selenium and PhantomJS. I'm trying to verify the captcha from Google reCaptcha 2.0 but it said that the captcha is not correct (solve more). It always happens to 100% and I've never got a passed captcha from Selenium.
See, as example on this picture:
Then when I click on "Verify"-Button, then this happend:
My python code:
self.driver.switch_to.frame(capcthaframe)
picturetable = self.driver.find_element_by_css_selector('.rc-imageselect-table-3')
images = []
for row in picturetable.find_elements_by_tag_name('tr'):
for col in row.find_elements_by_tag_name('td'):
images.append(col.find_element_by_tag_name('img'))
if images == []:
self.fail("Found no captcha images")
return -1
print "[*] Got answer : " + str(numbers)
for number in numbers:
index = int(number)-1
images[index].click()
print '[+] clicked on image '+str(index+1)
self.driver.save_screenshot('res.png')
time.sleep(1)
verifybutton = self.driver.find_element_by_id('recaptcha-verify-button')
verifybutton.click()
print "[*] Clicked verify button"
time.sleep(10)
I don't think that my code is wrong... So, have anybody a idea what's wrong with this reCaptcha error?

Related

How to solve the captcha enterprise?

I need to pass the captcha in steam, captcha kind Recaptcha v2 Enterprise, used the service 2recaptcha.com to pass the captcha, displays an error ERROR_CAPTCHA_UNSOLVABLE, the site itself is written that may require additional parameters such as the parameter s. I will show my code as an example:
def solve_recaptcha(data, url):
solver = TwoCaptcha(api_2captcha)
try:
result = solver.recaptcha(sitekey=data["sitekey"], url=url, enterprise=1, datas=data["datas"])
except Exception as ex:
print(f"Error during captcha solution: {ex}")
else:
return result
At first I made a mistake and didn't notice that captcha enterprise, captcha was solved but steam gave me an error, now when I started solving captcha like enterprise captcha, 2recaptcha site gives me an error.
What is my error and how can I solve it?
If I'm not using the right tools, which ones should I use?
I solved my problem with a while loop:
while True:
try:
result = solver.recaptcha(sitekey=data["sitekey"], url=url, enterprise=1, score=0.3)
except Exception as ex:
print(f"Error during captcha solution: {ex}")
else:
return result
The problem is not with your code. The error ERROR_CAPTCHA_UNSOLVABLE means that the captcha was not successfully solved. It's a normal error. List of errors: https://2captcha.com/2captcha-api#error_handling
from twocaptcha import TwoCaptcha
def solve_recaptcha(data, url):
solver = TwoCaptcha("your API")
try:
result = solver.recaptcha(sitekey=data["sitekey"], url=url, enterprise=1, datas=data["datas"])
except Exception as ex:
print(f"Error during captcha solution: {ex}")
else:
return result
The other problem I am facing is that on the Steam website, there is no 'submit' button under reCaptcha. Don't know how to pass it yet.
There is a tutorial on 2captcha website.
https://2captcha.com/2captcha-api#solving_recaptchav2_new
On their demo page where you solve a captcha, there is a submit button.

Anti-Captcha not working, validation happening before callback - Selenium

So, I'm trying to login in this website with Selenium:
https://carrinho.pontofrio.com.br/Checkout?ReturnUrl=%2fSite%2fMeusPedidos.aspx#login
And I'm using anti-captcha, here's my login code:
my_driver = webdriver.Chrome(executable_path=chrome_path)
wait = WebDriverWait(my_driver, 20)
#Realizar o Login
def login():
my_driver.get(url)
time.sleep(4)
my_driver.find_element_by_id('Email').send_keys(usuario)
my_driver.find_element_by_id('Senha').send_keys(senha)
my_driver.find_element_by_id('Senha').send_keys(Keys.ENTER)
time.sleep(1)
solver = recaptchaV2Proxyless()
solver.set_verbose(1)
solver.set_key("")
solver.set_website_url('https://carrinho.pontofrio.com.br/Checkout?ReturnUrl=%2fSite%2fMeusPedidos.aspx#login')
solver.set_website_key("6LfeX6kZAAAAAIhuSyQ1XRwZdOS26O-r4UJbW3y1")
# solver.set_data_s('"data-s" token from Google Search results "protection"')
g_response = solver.solve_and_return_solution()
if g_response != 0:
print("g-response: " + g_response)
else:
print("task finished with error " + solver.error_code)
time.sleep(1)
my_driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "%s"' % g_response)
time.sleep(1)
my_driver.execute_script(f"callbackCaptcha('{g_response}');")
login()
Website Key is correct, but the website is not accepting my Captcha responses.
So I've tried to check how the Login Process happens with the developer tools, and it goes like that:
The callback function happens after a function that I don't know what it that calls the website:
https://www.google.com/recaptcha/api2/userverify?k=6LfeX6kZAAAAAIhuSyQ1XRwZdOS26O-r4UJbW3y1
Post Method before callback method
And I'm not being able to find a way to simulate this post method, since Selenium doesn't do post methods.
Is there anyway that I can listen to all the Javascript events (the codes called) while running the page?
Any help would be much appreciated, thanks!
I was able to solve the validation thing, with the following code:
options.add_argument('--disable-blink-features=AutomationControlled')
But the Anti-Captcha is still giving me a wrong answer :(
I solved the problem
I've finally managed to resolve this myself. In case anyone else is struggling with a similar issue, here was my solution:
Open the console and execute the following cmd: ___grecaptcha_cfg.clients
Find the path which has the callback function, in my case it's ___grecaptcha_cfg.clients[0].O.O
Use the following code: driver.execute_script(f"___grecaptcha_cfg.clients[0].O.O.callback('{new_token}')") (Remember to change the path accordingly)
This Article will help you to find the ___grecaptcha_cfg.clients of your recaptcha site
driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "{}";'.format(g_response))
driver.execute_script(f"___grecaptcha_cfg.clients[0].O.O.callback('{g_response}')")
So yeah, I've discovered that there were 2 problems, first one being the validation, which I solved with this option:
options.add_argument('--disable-blink-features=AutomationControlled')
And the other one was that the website was generating a new token when I clicked the login button. So I decided to solve the captcha before asking to login, and using the callbackCaptcha to ask for login.

Issue with send_keys python selenium

I'm trying to make a little Facebook group auto post script using python and selenium
First of all I'm uploading 3/4 photos using the following code:
l = driver.find_elements_by_tag_name('input')
for g in l:
print(g)
try:
if g == driver.find_element_by_xpath("//input[#type='file']"):
print("Found")
logging.debug("Found input for image uploading")
g.send_keys(
'/var/www/html/v1/insta-post/AutoPostFB/images/0.jpg \n/var/www/html/v1/insta-post/AutoPostFB/images/1.jpg \n/var/www/html/v1/insta-post/AutoPostFB/images/2.jpg')
print("File/s Uploaded")
logging.debug("Images uploaded")
time.sleep(5)
# break
except:
print("Element not found after upload")
logging.debug("Element for upload not found")
Then I push the post text, since the textbox is already on focus
actions = ActionChains(driver)
actions.send_keys(info)
actions.perform()
time.sleep(1)
The issue is that every space in the info variable is abnormally converted into a return key
so if the text is like
info = "HEI HOW'S IS GOING?"
what I get in the textbox is
IS
GOING
HEY
HOW'S
Someone can help me out? I've tried like everything

Python Selenium Webpage fill: To download data from links

I've compiled this code to perform an iteration of downloads from a webpage which has multiple download links. Once the download link is clicked, the webpage produces a webform which has to be filled and submitted for the download to start. I've tried running the code and face issue in 'try'& 'except' block code (Error: Too broad exception clause) and towards the end there is an error associated with the 'submit' (Error: method submit maybe static) both of these subsequently result in 'SyntaxError: invalid syntax '. Any suggestions / help will be much appreciated. Thank you.
import os
from selenium import webdriver
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", os.getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-msdos-program")
driver = webdriver.Firefox(firefox_profile=fp)
driver.get('http://def.com/catalog/attribute')
#This is to find the download links in the webpage one by one
i=0
while i<1:
try:
driver.find_element_by_xpath('//*[#title="xml (Open in a new window)"]').click()
except:
i=1
#Once the download link is clicked this has to fill the form for submission which fill download the file
class FormPage(object):
def fill_form(self, data):
driver.find_element_by_xpath('//input[#type = "radio" and #value = "Non-commercial"]').click()
driver.find_element_by_xpath('//input[#type = "checkbox" and #value = "R&D"]').click()
driver.find_element_by_xpath('//input[#name = "name_d"]').send_keys(data['name_d'])
driver.find_element_by_xpath('//input[#name = "mail_d"]').send_keys(data['mail_d'])
return self
def submit(self):
driver.find_element_by_xpath('//input[#value = "Submit"]').click()
data = {
'name_d': 'abc',
'mail_d': 'xyz#gmail.com',
}
FormPage().fill_form(data).submit()
driver.quit()
Actually you have two warnings and a error:
1 - "Too broad exception" this is a warning telling you that you should except espefic errors, not all of them. In your "except" line should be something like except [TheExceptionYouAreTreating]: an example would be except ValueError:. However this should not stop your code from running
2 - "Error: method submit maybe static" this is warning telling you that the method submit is a static method (bassically is a method that don't use the self attribute) to supress this warning you can use the decorator #staticmethod like this
#staticmethod
def submit():
...
3 - "SyntaxError: invalid syntax" this is what is stopping your code from running. This is a error telling you that something is written wrong in your code. I think that may be the indentation on your class. Try this:
i=0
while i<1:
try:
driver.find_element_by_xpath('//*[#title="xml (Open in a new window)"]').click()
except:
i=1
#Once the download link is clicked this has to fill the form for submission which fill download the file
class FormPage(object):
def fill_form(self, data):
driver.find_element_by_xpath('//input[#type = "radio" and #value = "Non-commercial"]').click()
driver.find_element_by_xpath('//input[#type = "checkbox" and #value = "R&D"]').click()
driver.find_element_by_xpath('//input[#name = "name_d"]').send_keys(data['name_d'])
driver.find_element_by_xpath('//input[#name = "mail_d"]').send_keys(data['mail_d'])
return self
def submit(self):
driver.find_element_by_xpath('//input[#value = "Submit"]').click()
data = {
'name_d': 'abc',
'mail_d': 'xyz#gmail.com',
}
FormPage().fill_form(data).submit()
driver.quit()
One more thing. Those are really simple errors and warnings, you should be able to fix them by yourself by carefully reading what the error has to say. I also reccomend you reading about Exceptions

Selenium hanging on .click() in while loop

I am trying to download all of the spreadsheets from this website and the site requires me to click on the item and then click on a download button. The spreadsheets are all saved with the same id with an increasing number after each. I am trying to use a while loop to solve this problem but I am unsure if this is the best way to do this.
i = 0
while i < 13:
device = 'ctl00_LeftBarContent_lvLeftPanel_lbDevices_i' + str(i)
deviceElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(device))
deviceElement.click()
time.sleep(2)
downloadXpath = "ctl00_LeftBarContent_lvLeftPanel_btnDownload"
WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(downloadXpath)).click()
time.sleep(2)
i += 1
Currently, the code runs up to clicking the download button, the file downloads and then it seems to hang at the button and eventually times out. I am using the chrome driver.
Thanks!
This comment is just regarding your indentation. Either indent i, or de-indent all your code after i.
Incorrect Example 'Hello World':
i = 0
while i < 13:
print 'hello world'
i+=1
'error unexpected indent'
Correct Example 'Hello World':
i = 0
while i < 13:
print 'hello world'
i+=1
'Hello world'
'Hello world'
'Hello world'
'Hello world'
etc...
So for your problem, indent the problem correctly and retry. If you're still having issues, throw in some print statements before and after every command to see where you're getting stuck. Just a guess, but you may have to switch frames and then close the frame after the first download has completed.

Categories

Resources