TA的每日心情 | 开心 前天 07:08 |
---|
签到天数: 2032 天 连续签到: 2 天 [LV.Master]测试大本营
|
# coding:utf-8
from PIL import Image
import pytesseract
from PIL import ImageEnhance
from selenium import webdriver
from time import sleep
url='http://www.baidu.com'
driver = webdriver.Chrome()
driver.maximize_window() #将浏览器最大化
driver.get(url)
driver.find_element_by_xpath('//*[@id="u1"]/a[7]').click()
sleep(2)
driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_8__userName"]').click()
driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_8__userName"]').send_keys('xxxxxxx')
sleep(2)
#输入登录密码
driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_8__password"]').click()
driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_8__password"]').send_keys('xxxxxxx')
sleep(2)
driver.save_screenshot('E://123.png') #截取当前网页,该网页有我们需要的验证码
imgelement = driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_8__verifyCodeImg"]') #定位验证码
location = imgelement.location #获取验证码x,y轴坐标
size=imgelement.size #获取验证码的长宽
rangle=(int(location['x']),int(location['y']),int(location['x']+size['width']),int(location['y']+size['height'])) #写成我们需要截取的位置坐标
i=Image.open("E://123.png") #打开截图
frame4=i.crop(rangle) #使用Image的crop函数,从截图中再次截取我们需要的区域
frame4.save('E://frame4.jpg')
qq=Image.open('E://frame4.jpg')
#enhancer = ImageEnhance.Color(qq)
#enhancer = enhancer.enhance(0)
#enhancer = ImageEnhance.Brightness(enhancer)
#enhancer = enhancer.enhance(2)
#enhancer = ImageEnhance.Contrast(enhancer)
#enhancer = enhancer.enhance(8)
#enhancer = ImageEnhance.Sharpness(enhancer)
#qq = enhancer.enhance(20)
text= pytesseract.image_to_string(qq) #.strip() #使用image_to_string识别验证码
print text
Traceback (most recent call last):
File "D:/dataDrawing/sysTestTry/baiDuCheck1.py", line 37, in <module>
text= pytesseract.image_to_string(qq) #.strip() #使用image_to_string识别验证码
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
config=config)
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] |
|