Saving image element using splinter python

会有一股神秘感。 提交于 2019-12-11 10:10:03

问题


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:


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']


来源:https://stackoverflow.com/questions/34252836/saving-image-element-using-splinter-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!