亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python實(shí)現(xiàn)百萬答題自動(dòng)百度搜索答案

 更新時(shí)間:2018年01月16日 13:35:35   作者:書包的故事  
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)百萬答題自動(dòng)百度搜索答案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

用python搭建百萬答題、自動(dòng)百度搜索答案。

使用平臺(tái)

windows7
python3.6
MIX2手機(jī)

代碼原理

手機(jī)屏幕內(nèi)容同步到pc端
對問題截圖
對截圖文字分析
用瀏覽器自動(dòng)搜索文本

使用教程

1、使用Airdroid 將手機(jī)屏幕顯示在電腦屏幕上。也可使用360手機(jī)助手實(shí)現(xiàn)。不涉及任何代碼。實(shí)現(xiàn)效果如圖:

2、在提問出現(xiàn)時(shí),運(yùn)行python程序,將問題部分截圖。

這里要用到兩個(gè)函數(shù):

get_point()  #采集要截圖的坐標(biāo),以及圖片的高度寬度
window_capture()   #截圖

def get_point(): 
 '''''采集坐標(biāo),并返回w,h,x,y。 作為window_capture() 函數(shù)使用''' 
 try: 
 print('正在采集坐標(biāo)1,請將鼠標(biāo)移動(dòng)到該點(diǎn)') 
 # print(3) 
 # time.sleep(1) 
 print(2) 
 time.sleep(1) 
 print(1) 
 time.sleep(1) 
 x1,y1 = pag.position() #返回鼠標(biāo)的坐標(biāo) 
 print('采集成功,坐標(biāo)為:',(x1,y1)) 
 print('') 
 # time.sleep(2) 
 print('正在采集坐標(biāo)2,請將鼠標(biāo)移動(dòng)到該點(diǎn)') 
 print(3) 
 time.sleep(1) 
 print(2) 
 time.sleep(1) 
 print(1) 
 time.sleep(1) 
 x2, y2 = pag.position() # 返回鼠標(biāo)的坐標(biāo) 
 print('采集成功,坐標(biāo)為:',(x2,y2)) 
 #os.system('cls')#清除屏幕 
 w = abs(x1 - x2) 
 h = abs(y1 - y2) 
 x = min(x1, x2) 
 y = min(y1, y2) 
 return (w,h,x,y) 
 except KeyboardInterrupt: 
 print('獲取失敗') 

def window_capture(result,filename): 
 '''''獲取截圖''' 
 #寬度w 
 #高度h 
 #左上角截圖的坐標(biāo)x,y 
 w,h,x,y=result 
 hwnd = 0 
 hwndDC = win32gui.GetWindowDC(hwnd) 
 mfcDC = win32ui.CreateDCFromHandle(hwndDC) 
 saveDC = mfcDC.CreateCompatibleDC() 
 saveBitMap = win32ui.CreateBitmap() 
 MoniterDev = win32api.EnumDisplayMonitors(None,None) 
 #w = MoniterDev[0][2][2] 
 # #h = MoniterDev[0][2][3] 
 # w = 516 
 # h = 514 
 saveBitMap.CreateCompatibleBitmap(mfcDC,w,h) 
 saveDC.SelectObject(saveBitMap) 
 saveDC.BitBlt((0,0),(w,h),mfcDC,(x,y),win32con.SRCCOPY) 
 saveBitMap.SaveBitmapFile(saveDC,filename) 

運(yùn)行后截圖如下

3.對圖片文字分析提取

參考鏈接: * 圖片轉(zhuǎn)文本 * 配置方式

代碼部分:

def orc_pic(): 
 #識(shí)別中文 
 text=pytesseract.image_to_string(Image.open('jietu.jpg'),lang='chi_sim') 
 #識(shí)別英文 
 # text=pytesseract.image_to_string(Image.open('jietu.jpg')) 
 text = ''.join(text.split()) 
 return text 

4.對文本進(jìn)行搜索

 #瀏覽器搜索
url = 'http://www.baidu.com/s?wd=%s' % text
webbrowser.open(url)

所有代碼如下:

 #coding:'utf-8'
import win32gui, win32ui, win32con, win32api
from PIL import Image
import pytesseract
import webbrowser
#先下載pyautogui庫,pip install pyautogui
import os,time
import pyautogui as pag
#獲取sdk http://ai.baidu.com/。
#獲取aip pip install git+https://github.com/Baidu-AIP/python-sdk.git@master
from aip import AipOcr
import json

status=0
""" 你的 APPID AK SK """
APP_ID = '****'
API_KEY = '***'
SECRET_KEY = '***'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)

""" 讀取圖片 """

def get_question(path):
 '''百度識(shí)別圖片文字'''
 with open(path, 'rb') as fp:
 image=fp.read()
 res = client.basicGeneral(image)
 words = res['words_result']
 lines = [item['words'] for item in words]
 question = ''.join(lines)
 if question[1] == '.':
 question = question[2:]
 elif question[2] == '.':
 question = question[3:]
 return question.replace('?', ' ')
#采集坐標(biāo)
def get_point():
 '''采集坐標(biāo),并返回w,h,x,y。 作為window_capture() 函數(shù)使用'''
 try:
 print('正在采集坐標(biāo)1,請將鼠標(biāo)移動(dòng)到該點(diǎn)')
 # print(3)
 # time.sleep(1)
 print(2)
 time.sleep(1)
 print(1)
 time.sleep(1)
 x1,y1 = pag.position() #返回鼠標(biāo)的坐標(biāo)
 print('采集成功,坐標(biāo)為:',(x1,y1))
 print('')
 # time.sleep(2)
 print('正在采集坐標(biāo)2,請將鼠標(biāo)移動(dòng)到該點(diǎn)')
 print(3)
 time.sleep(1)
 print(2)
 time.sleep(1)
 print(1)
 time.sleep(1)
 x2, y2 = pag.position() # 返回鼠標(biāo)的坐標(biāo)
 print('采集成功,坐標(biāo)為:',(x2,y2))
 #os.system('cls')#清除屏幕
 w = abs(x1 - x2)
 h = abs(y1 - y2)
 x = min(x1, x2)
 y = min(y1, y2)
 return (w,h,x,y)
 except KeyboardInterrupt:
 print('獲取失敗')
#獲取截圖
def window_capture(result,filename):
 '''獲取截圖'''
 #寬度w
 #高度h
 #左上角截圖的坐標(biāo)x,y
 w,h,x,y=result
 hwnd = 0
 hwndDC = win32gui.GetWindowDC(hwnd)
 mfcDC = win32ui.CreateDCFromHandle(hwndDC)
 saveDC = mfcDC.CreateCompatibleDC()
 saveBitMap = win32ui.CreateBitmap()
 MoniterDev = win32api.EnumDisplayMonitors(None,None)
 #w = MoniterDev[0][2][2]
 # #h = MoniterDev[0][2][3]
 # w = 516
 # h = 514
 saveBitMap.CreateCompatibleBitmap(mfcDC,w,h)
 saveDC.SelectObject(saveBitMap)
 saveDC.BitBlt((0,0),(w,h),mfcDC,(x,y),win32con.SRCCOPY)
 saveBitMap.SaveBitmapFile(saveDC,filename)

def get_point_txt(status):
 #如果status=y,則重新獲取坐標(biāo)
 '''如果存在point.txt,則詢問是否重新采集,刪除point.txt;如果不存在txt,則直接采集。'''

 if not os.path.isfile('point.txt') :
 result = get_point()
 with open('point.txt', 'w') as f:
 f.write(str(result))
 return result
 else:
 if status=='y':
 result = get_point()
 with open('point.txt', 'w') as f:
 f.write(str(result))
 return result
 else:
 with open('point.txt', 'r') as f:
 result = f.readline()
 result = eval(result)
 return result

def orc_pic():
 #識(shí)別中文
 text=pytesseract.image_to_string(Image.open('jietu.jpg'),lang='chi_sim')
 #識(shí)別英文
 # text=pytesseract.image_to_string(Image.open('jietu.jpg'))
 text = ''.join(text.split())
 return text

#百度識(shí)別
def orc_baidu():
 text=get_question('jietu.jpg')
 return text

status='y'

start = time.time()
result=get_point_txt(status)
for i in range(10):
 window_capture(result,'jietu.jpg')

# text=orc_baidu()
text=orc_pic()
print(text)
#瀏覽器搜索
url = 'http://www.baidu.com/s?wd=%s' % text
webbrowser.open(url)
# url2='https://www.google.com/search?q=%s' % text

# webbrowser.open(url2)
end = time.time()
time=end-start
print('此次耗時(shí)%.1f秒' % time)

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python使用textract實(shí)現(xiàn)從各種文件中提取文本信息

    Python使用textract實(shí)現(xiàn)從各種文件中提取文本信息

    textract是一個(gè)強(qiáng)大的Python庫,可以用于從各種文件格式中提取文本,本文將介紹textract的使用場景,以及一些常用的Python代碼案例,希望對大家有所幫助
    2024-01-01
  • Python新年炫酷煙花秀代碼

    Python新年炫酷煙花秀代碼

    大家好,本篇文章主要講的是Python新年炫酷煙花秀代碼,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2022-01-01
  • pygame游戲之旅 添加碰撞效果的方法

    pygame游戲之旅 添加碰撞效果的方法

    這篇文章主要為大家詳細(xì)介紹了pygame游戲之旅的第7篇,教大家如何添加碰撞的效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Pytorch 統(tǒng)計(jì)模型參數(shù)量的操作 param.numel()

    Pytorch 統(tǒng)計(jì)模型參數(shù)量的操作 param.numel()

    這篇文章主要介紹了Pytorch 統(tǒng)計(jì)模型參數(shù)量的操作 param.numel(),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • Python數(shù)據(jù)處理利器Pandas?DataFrame常用操作

    Python數(shù)據(jù)處理利器Pandas?DataFrame常用操作

    這篇文章主要為大家介紹了Python數(shù)據(jù)處理利器Pandas?DataFrame,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • Python實(shí)現(xiàn)的knn算法示例

    Python實(shí)現(xiàn)的knn算法示例

    這篇文章主要介紹了Python實(shí)現(xiàn)的knn算法,結(jié)合實(shí)例形式詳細(xì)分析了Python實(shí)現(xiàn)knn算法的原理與相關(guān)操作技巧,并附帶給出了statsmodels模塊與pandas模塊的下載、安裝操作方法,需要的朋友可以參考下
    2018-06-06
  • Python批量按比例縮小圖片腳本分享

    Python批量按比例縮小圖片腳本分享

    這篇文章主要介紹了Python批量按比例縮小圖片腳本分享,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-05-05
  • python pdb調(diào)試方法分享

    python pdb調(diào)試方法分享

    在交互環(huán)境中通常使用pdb.run來調(diào)試,下面學(xué)習(xí)一下使用方法,大家參考使用吧
    2014-01-01
  • Pytorch?linear?多維輸入的參數(shù)問題

    Pytorch?linear?多維輸入的參數(shù)問題

    這篇文章主要介紹了Pytorch?linear多維輸入的參數(shù)的問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • 基于Python繪制子圖及子圖刻度的變換等的問題

    基于Python繪制子圖及子圖刻度的變換等的問題

    這篇文章主要介紹了基于Python繪制子圖及子圖刻度的變換等的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-05-05

最新評論