失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python自动答题助手_头脑王者python答题助手

python自动答题助手_头脑王者python答题助手

时间:2019-01-22 13:23:32

相关推荐

python自动答题助手_头脑王者python答题助手

参考了这些资料ZLOE:知乎答题王全自动程序​基于Python的头脑王者脚本(纯娱乐) - CSDN博客​python中文件变化监控-watchdog - CSDN博客​

基本思路:fiddler抓包,存文件,百度搜结果,显示各个答案的结果数,手动答题。碰到自己不会的题,一般地,正向问题就选结果数最多的,反向问题(题干一般含“不”字)就选结果最少的。碰到自己本来就会的题,也能预先知道正确答案的位置顺序,让答题更快。

使用了watchdog检测文件变化,只有当获取到新题才开始输出,而不会一直刷个不停,不过现在fiddler进行一次save会输出两次而不是一次,原因暂不清楚。

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import json

from urllib import parse

import requests

import os

import time

from bs4 import BeautifulSoup as BS

from watchdog.observers import Observer

from watchdog.events import *

# 存入题库,自行决定,是否启用

# import sqltiku

def get_appinf(filename):

f = open(filename, 'r', encoding='utf-8')

try:

print('file loaded')

j = json.loads(f.read())

#print(j)

if 'quiz' in j['data'] and 'options' in j['data']:

num = j['data']['num']

quiz = j['data']['quiz']

print(('第' + str(num) + '题:' + quiz).center(50, '*') + '\n')

cho = j['data']['options']

lei = j['data']['school']

ke = j['data']['type']

zuo = j['data']['contributor']

ti = quiz

a = cho[0]

b = cho[1]

c = cho[2]

d = cho[3]

find_data = '无'

# 存入数据库

# sqltiku.find_sql(lei, ke, zuo, ti, a, b, c, d, find_data)

else:

pass

return quiz, cho

except:

print('get_appinf error')

pass

f.close()

def baidu(question, answers):

url = '/s'

headers = {

'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1'

}

data = {

'wd': question

}

res = requests.get(url, params=data, headers=headers)

res.encoding = 'utf-8'

html = res.text

for i in range(len(answers)):

#c = html.count(answers[i])

answers[i] = (i+1,answers[i],html.count(answers[i]))

#print('选项' + (i+1) + ' ' + 'N' + '个结果')

#answers.sort(reverse=True)

#print(answers[0][0] + ' ' + answers[0][1])

print(answers[0])

print(answers[1])

print(answers[2])

print(answers[3])

return answers

class FileEventHandler(FileSystemEventHandler):

def on_modified(self, event):

if event.is_directory:

print("directory modified:{0}".format(event.src_path))

else:

print("file modified:{0}".format(event.src_path))

main()

def main():

try:

# 你在抓包程序中填的目录

print('try')

que, cho = get_appinf(r'C:\www\responsebody.txt')

#print(que)

baidu(que, cho)

except:

pass

# 点击再来一次,自己决定是否启用

# os.system('adb shell input swipe 506 1363 506 1363')

# 选择挑战种类,这里你得自己调整啦

# os.system('adb shell input swipe 526 759 526 759')

if __name__ == '__main__':

print('程序运行中...........')

main()

observer = Observer()

event_handler = FileEventHandler()

observer.schedule(event_handler,"c:/www/",True)

observer.start()

while True:

#print('waiting new quiz...')

time.sleep(1)

如果觉得《python自动答题助手_头脑王者python答题助手》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。