#!/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()