# 通过base64

 

from selenium import webdriver
import cv2
import base64
import numpy as np


driver = webdriver.Chrome()
driver.get('http://www.baidu.com')

index64 = driver.get_screenshot_as_base64()
indexstring = base64.b64decode(index64)
nparr = np.frombuffer(indexstring, np.uint8)
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('gray', image_gray)
cv2.waitKey(0)

  

 

 

#通过png, pillow,

from selenium import webdriver
import numpy as np
from PIL import Image
from io import BytesIO
import cv2

driver = webdriver.Chrome()
index = driver.get('http://www.baidu.com')
scr = driver.get_screenshot_as_png()
scr = Image.open(BytesIO(scr))
scr = np.asarray(scr, dtype=np.float32).astype(np.uint8)
scr = cv2.cvtColor(scr, cv2.COLOR_BGR2GRAY)
cv2.imshow('gray', scr)
cv2.waitKey(0)

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-01-17
猜你喜欢
  • 2021-11-06
  • 2022-12-23
  • 2021-08-10
  • 2022-12-23
  • 2021-12-08
  • 2021-12-29
  • 2021-12-26
相关资源
相似解决方案