driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://admin-ceshi.eyyb.vip:81/login')
# driver.get("http://admin-stable.eyyb.vip/login")
def VerficationCode(self):
self.driver.get_screenshot_as_file(datapath+"pic.png")
img_path=datapath+'pic.png'
#导入有验证码的截图
im1=Image.open(img_path)
img_size=im1.size
print("{}".format(img_size))
x=1020 #找到验证码的位置
y=320
w=100
h=50
region=im1.crop((x,y,x+w,y+h)) #截取图片上验证码区域
region.save(datapath+"test1.png") #保存图片
im2=Image.open(datapath + "test1.png")
img2=im2.resize((200,200)) #存放元组
img=img2.convert('P') #转换图像模式(锐化、复古)
verficationcode=pytesseract.image_to_string(img)
图片如下
本文仅用来记录作为我的学习笔记