本文介绍了使用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()

推荐答案

@alecxe答案的其他说明:
splinter没有用于获取Web元素属性的接口(即get_attribute方法).

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

使用以下代码使用splinter获取验证码的src:

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

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


编辑:感谢@Jérémie!
要获取src属性值,请使用以下命令:


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

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

这篇关于使用splinter python保存图像元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 14:21