Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constantly receiving Not solved while using fromdriver #27

Closed
longinteger017 opened this issue Oct 24, 2020 · 8 comments
Closed

Constantly receiving Not solved while using fromdriver #27

longinteger017 opened this issue Oct 24, 2020 · 8 comments
Assignees
Labels
CNS The problem where the result is constantly "Not solved". good first issue Good for newcomers

Comments

@longinteger017
Copy link

The following keeps returning Not solved for me. I have never got any other return.

import selenium
from amazoncaptcha import AmazonCaptcha
from selenium import webdriver as webdriver

d = webdriver.Chrome(ChromeDriverManager().install())
captcha = AmazonCaptcha.fromdriver(d)
print(captcha.solve(keep_logs=True))

not-solved-captcha.log:
https://images-na.ssl-images-amazon.com/captcha/bfhuzdtn/Captcha_cebmxydbrt.jpg
https://images-na.ssl-images-amazon.com/captcha/perumqgc/Captcha_gaommpndkq.jpg
https://images-na.ssl-images-amazon.com/captcha/rhnrlggh/Captcha_tijaodpupx.jpg
https://images-na.ssl-images-amazon.com/captcha/bysppkyq/Captcha_xroxbnvmrg.jpg

@longinteger017 longinteger017 added the training data A user wants to provide additional training data label Oct 24, 2020
@a-maliarov
Copy link
Owner

Hi, just to clarify, everything works fine, but these 4 images, which you sent links for, are Not solved, right?

OR: do you receive Not solved not only for the images you sent, but just constantly?

Didn't get it, sry. Let me know, thanks!

@longinteger017
Copy link
Author

Hi, sorry for my miscommunication.

As for me, the algorithm hasn't solved any captcha yet. I tried like 20 different times and all cases returned Not Solved.
It didn't work constantly. Never worked for me.

Do the 4 .jpg work for you?

@a-maliarov
Copy link
Owner

These four links are working fine for me, I assume that the problem is connected to how captcha image is displayed in your browser (because fromdriver class method takes a screenshot and then crops the captcha image).

Try another class method - fromlink. This will use the captcha image link, therefore it will be not relevant how the image is displayed in the browser.

Here is the example with those four links:

from amazoncaptcha import AmazonCaptcha

links = [
    'https://images-na.ssl-images-amazon.com/captcha/bfhuzdtn/Captcha_cebmxydbrt.jpg',
    'https://images-na.ssl-images-amazon.com/captcha/perumqgc/Captcha_gaommpndkq.jpg',
    'https://images-na.ssl-images-amazon.com/captcha/rhnrlggh/Captcha_tijaodpupx.jpg',
    'https://images-na.ssl-images-amazon.com/captcha/bysppkyq/Captcha_xroxbnvmrg.jpg'
]

for link in links:    
    captcha = AmazonCaptcha.fromlink(link)
    print(captcha.solve())

@a-maliarov
Copy link
Owner

a-maliarov commented Oct 25, 2020

So, in your code, when you are on the page with captcha, instead of using fromdriver, firstly extract the captcha image link and then use fromlink. Since it is the first img at the page, it is not obligatory to use BautifulSoup, but you can do the extraction your way. The main point is to just get the captcha link.

Here is the example of what I mean:

from webdriver_manager.chrome import ChromeDriverManager
from amazoncaptcha import AmazonCaptcha
from selenium import webdriver

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.amazon.com/errors/validateCaptcha')

captcha_link = driver.page_source.split('<img src="')[1].split('">')[0]   # extract captcha link
captcha = AmazonCaptcha.fromlink(captcha_link)                            # pass it to `fromlink` class method
print(captcha.solve())

@longinteger017
Copy link
Author

Perfect solution and explanation. Just tested it. Works like a charm.

Thank you very much!

@a-maliarov a-maliarov added CNS The problem where the result is constantly "Not solved". good first issue Good for newcomers and removed training data A user wants to provide additional training data labels Oct 25, 2020
@a-maliarov a-maliarov changed the title simple request keeps returning not solved Constantly receiving Not solved while using fromdriver Oct 25, 2020
@a-maliarov a-maliarov pinned this issue Oct 25, 2020
@a-maliarov a-maliarov changed the title Constantly receiving Not solved while using fromdriver Constantly receiving Not solved while using fromdriver class method Oct 25, 2020
@a-maliarov a-maliarov changed the title Constantly receiving Not solved while using fromdriver class method Constantly receiving Not solved while using fromdriver Oct 25, 2020
@a-maliarov
Copy link
Owner

No problems, have a great day!

@Dohzer43
Copy link

Dohzer43 commented Nov 4, 2020

This solution also worked for me! Thank You

@sfilargi
Copy link

I was hitting the same. @Dohzer43 @longinteger017 can you verify if you are using a high DPI monitor with DPI scaling?

In my case the problem seems to be that in fromdriver we do the following:

        location = element.location
        size = element.size
        left = location['x']
        top = location['y']
        right = location['x'] + size['width']
        bottom = location['y'] + size['height']

But because my monitor is configured for high dpi + dpi scaling, the coordinates were not matching to the PNG captured. Multiplying everything by 2, solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CNS The problem where the result is constantly "Not solved". good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants