Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to download captcha image with Python Selenium and Requests
img = driver.find_element_by_xpath("//div[@id='MailRuConfirm']/div/div[18]/form/div[1]/div[2]/div[2]/div[2]/img")
src = img.get_attribute('src')
img = requests.get(src)
with open('captcha.jpg', 'wb') as f:
f.write(img.content)
@haxshaan

This comment has been minimized.

Copy link

haxshaan commented Nov 14, 2017

This isn't helping in my case. As I am facing a kind of dynamic url.
Everytime I get the element's src and save the content, I get a new image.

@THUzhangga

This comment has been minimized.

Copy link

THUzhangga commented Aug 2, 2019

This isn't helping in my case. As I am facing a kind of dynamic url.
Everytime I get the element's src and save the content, I get a new image.

Well, perhaps you can use selenium to save the screen, and then crop the image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.