Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用splinter python保存图像元素_Python_Selenium_Splinter - Fatal编程技术网

使用splinter python保存图像元素

使用splinter python保存图像元素,python,selenium,splinter,Python,Selenium,Splinter,如何将图像图片保存到文件?我试过这种方法,但我有一个错误。 代码是: 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")

如何将图像图片保存到文件?我试过这种方法,但我有一个错误。 代码是:

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
方法)

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

script=“document.getElementById('recaptcha\u challenge\u image').src”
src=browser.evaluate\u脚本(脚本)

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


是的。browser.find_by_id('recaptcha_challenge_image')['src']@Jérémie答案已更新,但我的答案只是另一个被删除答案的补充说明:|是的,另一个答案在我昨天发表评论后被删除:)我希望这不是我说的话!
 src = browser.find_by_id('recaptcha_challenge_image')['src']