简体   繁体   中英

Saving image element using splinter python

How can I save image picture to a file? i tried this way but i have an error. the code is :

from splinter import Browser
import time

with Browser() as browser:
url = "https://password.gmx.com/"
browser.visit(url)
captcha=browser.find_by_id('recaptcha_challenge_container')
output = open ("image.jpg","wb")
output.write(captcha)
output.close()

Additional note to @alecxe's answer:
splinter doesn't have an interface for getting attribute of web element (ie get_attribute method).

Use the following code for getting src of captcha using splinter :

script = "document.getElementById('recaptcha_challenge_image').src"
src = browser.evaluate_script(script)

EDIT : Thanks to @Jérémie!
To get src attribute value use following:

 src = browser.find_by_id('recaptcha_challenge_image')['src']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM