Selenium Webdriver,屏幕截图为numpy数组(Python) [英] Selenium Webdriver, screenshot as numpy array (Python)
本文介绍了Selenium Webdriver,屏幕截图为numpy数组(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用Selenium Webdriver截屏并将其转换为numpy数组而不是保存它?我需要在openCV中使用它.
Is there a way to take a screenshot with selenium webdriver and convert in to a numpy array instead of saving it? I need to use it with openCV.
注意:我不想保存图像并再次打开它
Note: I don't want to save the image and open it again
推荐答案
我确定有一种更有效的方法,但这对我有用:
I'm sure there is a more efficient way of doing this, but this is what worked for me:
from selenium import webdriver
from PIL import Image
import StringIO
import numpy as np
browser = webdriver.Firefox()
browser.get('https://www.google.ca/?gws_rd=ssl')
data = browser.get_screenshot_as_png()
img = Image.open(StringIO.StringIO(data))
numpy_array = np.asarray(img)
这篇关于Selenium Webdriver,屏幕截图为numpy数组(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文