一、截取图片验证码
from selenium import webdriver from PIL import Image # 先要安装:pip install Pillow driver=webdriver.Chrome() driver.get("http://10.9.17.240:8080/#/login") driver.save_screenshot("d:/before.png") # 保存整个页面 code_element=driver.find_element_by_xpath("//*[@class='el-row']/div[2]/img") print(code_element.location) # 输出{'x': 509, 'y': 504} left=code_element.location['x'] top=code_element.location['y'] right=left+code_element.size['width'] bottom=top+code_element.size['height'] im=Image.open("d:/before.png") # 打开保存的图片 img= im.crop((left, top, right, bottom)) # 从整个页面截取验证码图片 img.save("d:/after.png") #保存截取后的图片