python 實(shí)現(xiàn)截圖自動(dòng)存入Excel表
首先我先在桌面新建一個(gè)test.xls文件
import keyboard #監(jiān)聽按鍵庫(kù)
from PIL import ImageGrab #圖像處理庫(kù)
import time
from aip import AipOcr #pip install baidu_aip\
import xlwt
biao = xlwt.Workbook()
worksheet = biao.add_sheet('sheet1')
# print("開始截圖")
# 1. 截取圖片
num=0
while 1:
keyboard.wait(hotkey='ctrl+alt+a')
print("鍵盤按下了'ctrl+alt+a'")
keyboard.wait('enter')
print("鍵盤按下了'enter'")
# 模擬延遲,來(lái)解決grabclipboard函數(shù)的緩存問(wèn)題(grabclipboard函數(shù)操作太快,它就會(huì)讀取上一次的內(nèi)容)
time.sleep(0.1)
# 2. 保存圖片到電腦上
image = ImageGrab.grabclipboard()
image.save('screen%s.png'%(num))
# 3. 調(diào)用百度AI識(shí)別圖片內(nèi)容
APP_ID = '你的APP_ID'
API_KEY = '你的API_KEY'
SECRET_KEY = '你的SECRET_KEY'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
# 獲取圖片的二進(jìn)制數(shù)據(jù)
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('screen%s.png'%(num))
""" 調(diào)用通用文字識(shí)別(高精度版) """
text = client.basicAccurate(image)
textList = text['words_result']
print(textList)
num1 = 0
for i in textList:
worksheet.write(num, num1, i['words'])
biao.save('C:\\Users\\mxy\\Desktop\\test.xls')
num1 += 1
num+=1
print("結(jié)束截圖")
-
Excel
+關(guān)注
關(guān)注
4文章
218瀏覽量
55527 -
python
+關(guān)注
關(guān)注
56文章
4797瀏覽量
84691
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論