当前位置:   article > 正文

python自动答题脚本程序_python 自动答题

python 自动答题

python自动答题脚本程序


import requests
import os
from PIL import Image
from aip import AipOcr

#手机截图.图片预处理
def get_screenshot():
    # 截屏
    os.system('adb shell screencap -p /sdcard/image.png')
    os.system('adb pull /sdcard/image.png')

#文字识别
def get_word_by_img():
    # 文字识别
    APP_ID = '16227766'
    API_KEY = 'FgubvnxtReF32vR4jGsS4FY4'
    SECRET_KEY = 'R5YbhWyY2NMF102wRZTwVm9U4hjeAwQG'
    client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
    i = open(r'D:\dati\new_img_fb.png', 'rb')
    img = i.read()
    img_res = client.basicGeneral(img)
    return img_res

#百度:使用requests进行访问
def baidu(question, answers):
    # 进行百度
    url = 'https://www.baidu.com/s'

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'
    }
    data = {
        'wd': question
    }
    res = requests.get(url=url, params=data, headers=headers)
    res.encoding = 'utf-8'
    html = res.text
    for i in range(len(answers)):
        answers[i] = (html.count(answers[i]), answers[i], i)
    answers.sort(reverse=True)
    return answers

def run():
    while True:
        input("回车答题")
        get_screenshot()
        img = Image.open('D:\dati\image.png')
        title_img = img.crop((80, 500, 1000, 880))
        answers_img = img.crop((80, 960, 1000, 1720))
        new_img = Image.new('RGBA', (920, 1140))
        new_img.paste(title_img, (0, 0, 920, 380))
        new_img.paste(answers_img, (0, 380, 920, 1140))
        new_img.save('new_img_fb.png')

#找答案
        info = get_word_by_img()
        answers = [x['words'] for x in info['words_result'][-4:]]
        question = ''.join([x['words'] for x in info['words_result'][:-4]])
        resy = baidu(question, answers)
        print(resy)

if __name__ == '__main__':
    run()


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/995932
推荐阅读
相关标签
  

闽ICP备14008679号