用 python 做得答案助手,题库接口来自 超星网课脚本 。
python运行效率太慢,又做了一个 go语言版。


原理

post 提交问题

获取 json 题目和答案字段 格式化输出

目前集成了 4个 接口
不保证以后 一直能用

python

python 解释型语言,代码简单,库全。

python版

# -*- coding: utf-8 -*-
from requests import post
from json import loads

def chaxun1(wenti):
    url = "http://cx.beaa.cn/cx.php"
    data = {'content': wenti}
    res = post(url=url,data=data)
    if res.status_code == int("200") :
      res = res.text
      print("-----------\n接口1:")
      res = loads(res)
      title = res["title"]
      print("题目是:"+title)
      answer = res["answer"]
      print("答案是:\n"+answer+"\n")
    else:
      print('-----------\n接口1错误'+str(res.status_code))

def chaxun2(wenti):
    url = "http://cx.icodef.com/wyn-nb"
    data = {'question': wenti}
    res = post(url=url,data=data)
    if res.status_code == int("200") :
      res = res.text
      print("-----------\n接口2:")
      res = loads(res)
      answer = res["data"]
      print("答案是:\n"+answer+"\n")
    else:
      print('-----------\n接口2错误'+str(res.status_code))

def chaxun3(wenti):
    url = "http://api.902000.xyz:88/wkapi.php"
    data = {'q': wenti}
    res = post(url=url,data=data)
    if res.status_code == int("200") :
      res = res.text
      print("-----------\n接口3:")
      res = loads(res)
      title = res["tm"]
      print("题目是:"+title)
      answer = res["answer"]
      print("答案是:\n"+answer)
    else:
      print('-----------\n接口3错误'+str(res.status_code))

def chaxun4(wenti):
    url = "http://api.xmlm8.com/tk.php"
    data = {'t': wenti}
    res = post(url=url,data=data)
    if res.status_code == int("200") :
      res = res.text
      print("-----------\n接口4:")
      res = loads(res)
      title = res["tm"]
      print("题目是:"+title)
      answer = res["da"]
      print("答案是:\n"+answer)
    else:
      print('-----------\n接口4错误'+str(res.status_code))

f = 1
print("本程序 制作 by z7l \n 接口来自互联网 \n 目前题库仅适用于超星网课")
while f==1:
  wenti = input(u'\n请输入问题: 输入\'q\'退出\n')
  if wenti == 'q':
    f = 0
  else:
    chaxun1(wenti)
    chaxun2(wenti)
    chaxun3(wenti)
    chaxun4(wenti)
    print("-----查询结束----\n")

打包

一个小图标 cx.ico

pyinstaller -F -i cx.ico daan.py

文件下载

答案助手1.5.exe

go

换为效率更快的go 语言, json处理来自thedevsaddam/gojsonq ,我设置的位置是 github/gojsonq

go 语言版

package main

import (
   "fmt"
   "net/http"
   "strings"
   "io/ioutil"
   "github/gojsonq"
)

func main() {
   var wenti string
   var url = [4]string{"http://cx.beaa.cn/cx.php", "http://cx.icodef.com/wyn-nb", "http://api.902000.xyz:88/wkapi.php", "http://api.xmlm8.com/tk.php"}
   var data = [4]string{"content", "question", "q", "t"}
   var answer = [4]string{"answer", "data", "answer", "da"}
   var timu = [4]string{"title", "", "tm", "tm"}
   fmt.Println("本程序 制作 by z7l \n 接口来自互联网 \n 目前题库仅适用于超星网课")
   for true {
      fmt.Println("\n请输入问题:")
      fmt.Scanln(&wenti)
      for i := 0; i < 4; i++ {
         fmt.Println("---------\n 接口", i)
         PostData(wenti,url[i],data[i],answer[i],timu[i])
      }
      fmt.Println("\n-----查询完毕-----")
   }
}


func PostData(wenti,url,question,answer,timu string){
   resp, err := http.Post(url,"application/x-www-form-urlencoded",strings.NewReader(question+"="+wenti))
   if err != nil {
       fmt.Println(err.Error())
   }
   body, err := ioutil.ReadAll(resp.Body)
   if err != nil {
       fmt.Println(err)
   }
   res :=gojsonq.New().FromString(string(body)).Find(timu)
    fmt.Println("题目:  ", res)
   res =gojsonq.New().FromString(string(body)).Find(answer)
    fmt.Println("答案:  ", res)
}

打包

go build daan.go

文件下载

答案助手2.1.exe