Saving image element using splinter python

2019-08-09 02:32发布

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()

1条回答
可以哭但决不认输i
2楼-- · 2019-08-09 03:17

Additional note to @alecxe's answer:
splinter doesn't have an interface for getting attribute of web element (i.e. 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']
查看更多
登录 后发表回答