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()


  • 8
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码猩

如果可以请支持我一下哟!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值