Skip to content

Instantly share code, notes, and snippets.

@YCF
Forked from l1905/listen.py
Created January 20, 2018 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YCF/e9abe44e7817a3eededd503ffd30258d to your computer and use it in GitHub Desktop.
Save YCF/e9abe44e7817a3eededd503ffd30258d to your computer and use it in GitHub Desktop.
头脑王者答题辅助(https://github.com/chxj1992/hortor_cheater, 将作者的listen.py替换即可)
import re
import json
from mitmproxy import ctx
from urllib.parse import quote
import string
import requests
def response(flow):
path = flow.request.path
if path == '/question/bat/findQuiz':
content = flow.response.content
data = json.loads(content)
question = data['data']['quiz']
options = data['data']['options']
ctx.log.info('question : %s, options : %s'%(question, options))
options = ask(question, options)
data['data']['options'] = options
flow.response.text = json.dumps(data)
def ask(question, options):
url = quote('http://www.baidu.com/s?wd=' + question, safe = string.printable)
content = requests.get(url).text
c=[0,0,0,0]
for i in range(len(options)):
option = options[i]
count = content.count(option)
c[i]=count
ctx.log.info('option : %s, count : %s'%(option, count))
options[i] = options[i] + ':'+ str(count)
options[c.index(max(c))] = '--> '+options[c.index(max(c))]
return options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment