Selenium accesses Baidu and then gets a screenshot of the Baidu logo

#!/usr/bin/env python  
# encoding: utf-8
import time
from selenium import webdriver
from PIL import Image
from io import BytesIO
driver=webdriver.Chrome()
driver.get("http://www.baidu.com/")
img=driver.find_element_by_xpath("//div/img")
location=img.location
size=img.size
x=location["x"]
y=location["y"]
height=size["height"]
wid=size["width"]
im=Image.open(BytesIO(driver.get_screenshot_as_png()))
im.show()
box=(x,y,x+wid,y+height) #These four parameters represent the x, y in the upper left corner of the coordinates to be intercepted, and the x, y in the lower right corner of y
captcha=im.crop(box) #Intercept the area specified above
captcha.show()

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324964453&siteId=291194637