[Python] 纯文本查看 复制代码
import tkinter as tk
from tkinter import ttk
import requests,os,urllib3,time,hashlib,json
from lxml import etree
class PyWinDesign:
def __init__(self, 启动窗口):
self.启动窗口 = 启动窗口
self.启动窗口.title('学小易查题接口PC ——by 浅山藏')
self.启动窗口.resizable(width=True, height=True)
screenwidth = self.启动窗口.winfo_screenwidth()
screenheight = self.启动窗口.winfo_screenheight()
size = '%dx%d+%d+%d' % (596, 430, (screenwidth - 596) / 2, (screenheight - 430) / 2)
self.启动窗口.geometry(size)
self.标签1_标题 = tk.StringVar()
self.标签1_标题.set('账号:')
self.标签1 = tk.Label(self.启动窗口,textvariable=self.标签1_标题,anchor=tk.W)
self.标签1.place(x=380,y=19,width=35,height=25)
self.标签2_标题 = tk.StringVar()
self.标签2_标题.set('密码:')
self.标签2 = tk.Label(self.启动窗口,textvariable=self.标签2_标题,anchor=tk.W)
self.标签2.place(x=381,y=50,width=36,height=27)
self.编辑框1 = tk.Text(self.启动窗口,wrap=tk.NONE)
self.编辑框1.insert(tk.END,'')
self.编辑框1.place(x=438,y=19,width=150,height=25)
self.编辑框2_标题 = tk.StringVar()
self.编辑框2 =tk.Entry(self.启动窗口, textvariable=self.编辑框2_标题, show='*')
self.编辑框2.place(x=438,y=54,width=150,height=25)
self.按钮1_标题 = tk.StringVar()
self.按钮1_标题.set('登录')
self.按钮1 = tk.Button(self.启动窗口,textvariable=self.按钮1_标题,command=self.按钮1_被鼠标左键单击)
self.按钮1.place(x=483,y=90,width=56,height=41)
self.编辑框3 = tk.Text(self.启动窗口,wrap=tk.NONE)
self.编辑框3.insert(tk.END,'')
self.编辑框3.place(x=22,y=26,width=332,height=55)
self.按钮2_标题 = tk.StringVar()
self.按钮2_标题.set('查题')
self.按钮2 = tk.Button(self.启动窗口,textvariable=self.按钮2_标题,command=self.按钮2_被鼠标左键单击)
self.按钮2.place(x=40,y=92,width=80,height=40)
self.按钮3_标题 = tk.StringVar()
self.按钮3_标题.set('备用查题')
self.按钮3 = tk.Button(self.启动窗口,textvariable=self.按钮3_标题,command=self.按钮3_被鼠标左键单击)
self.按钮3.place(x=250,y=92,width=80,height=40)
self.编辑框4_滚动条_纵 = tk.Scrollbar(self.启动窗口)
self.编辑框4_滚动条_纵.place(x=568,y=147,width=18,height=275)
self.编辑框4 = tk.Text(self.启动窗口,yscrollcommand=self.编辑框4_滚动条_纵.set,wrap=tk.WORD)
self.编辑框4_滚动条_纵.config(command=self.编辑框4.yview)
self.编辑框4.insert(tk.END,'')
self.编辑框4.place(x=13,y=147,width=555,height=275)
url = 'http://www.iyuji.cn/iyuji/s/anZ1T2k2UG9Hak1FdHhmalZ5YmpiUT09/1593538728082638'
req = requests.get(url).text
html = etree.HTML(req)
txts = html.xpath('//*[@class="vp_text"]/p')
ti = ''
for txt in txts:
txt = txt.xpath('.//text()')[0]
ti = ti + txt + '\n'
self.编辑框4.insert(tk.END,ti)
self.编辑框4.insert(tk.END,'\n')
if os.path.exists('.\\token.txt'):
self.编辑框4.insert(tk.END,'检测到token,无需登录,若查题失败请尝试重新登录\n本软件只调用接口,如若封号,概不负责\n备用查题无需登录,但题量可能较少\n——by 浅山藏')
f = open('token.txt')
global token
token = f.read()
else:
self.编辑框4.insert(tk.END,'请先用学小易账号密码进行登录\n本软件只调用接口,如若封号,概不负责\n备用查题无需登录,但题量可能较少\n——by 浅山藏')
def 按钮1_被鼠标左键单击(self):
self.编辑框4.delete('1.0','end')
user = self.编辑框1.get('0.0','end')
password = self.编辑框2.get()
url = 'https://app.51xuexiaoyi.com/api/v1/login'
data = {
'username':user,
'password':password
}
t_t = str(int(time.time()*1000))
headers ={
"Host":"app.51xuexiaoyi.com",
'device': 'Al5tmwTm9rTIOttQ3xHaJ00afNLO15wEkPnMUK3W_xce',
'platform': 'android',
'app-version': '1.0.6',
't':t_t,
's':'939aea07176a02feba86a1b277d9a129',
'Accept-Encoding': "gzip",
'User-Agent': 'okhttp/3.11.0'
}
req = requests.post(url,headers=headers,data=data,timeout=20).json()
code = req['code']
if code ==200:
self.编辑框4.delete('1.0','end')
self.编辑框4.insert(tk.END,'登录成功\n——by 浅山藏')
global token
token = req['data']['api_token']
f = open('token.txt','w')
f.write(token)
f.close()
else:
self.编辑框4.insert(tk.END,'登录失败,请检查账号密码重试\n——by 浅山藏')
def 按钮2_被鼠标左键单击(self):
try:
self.编辑框4.delete('1.0','end')
keyword = self.编辑框3.get('0.0','end')
url ='https://app.51xuexiaoyi.com/api/v1/searchQuestion'
global token
t_t = str(int(time.time()*1000))
headers = {
"Host":"app.51xuexiaoyi.com",
'token': token,
'device': 'Al5tmwTm9rTIOttQ3xHaJ00afNLO15wEkPnMUK3W_xce',
'platform': 'android',
'app-version': '1.0.6',
't':t_t,
's':'939aea07176a02feba86a1b277d9a129',
'Accept-Encoding': "gzip",
'User-Agent': 'okhttp/3.11.0'
}
data = {
"keyword":keyword
}
req = requests.post(url,headers=headers,data=data,timeout=20).json()
answers = ''
for i in range (0,len(req['data'])):
question = req['data'][i]['q']
answer = req['data'][i]['a']
answers = answers + '题目:'+question + '\n' +'答案:'+ answer +'\n\n'
self.编辑框4.insert(tk.END,answers)
except:
hui = req['msg']+'\n'+'如果您被封号,请不要再使用本版本,十分抱歉\n可以采用备用查题进行查题\n ——by.浅山藏'
self.编辑框4.insert(tk.END,hui)
def 按钮3_被鼠标左键单击(self):
try:
try:
self.编辑框4.delete('1.0','end')
keyword = self.编辑框3.get('0.0','end')
url = 'http://tiku.xuexibao.tech/api/mobile/Index/searchQuestion'
headers = {
'authorization':'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vdGlrdS54dWV4aWJhby50ZWNoL2FwaS9tb2JpbGUvSW5kZXgvYXBwTG9naW4iLCJpYXQiOjE1OTM0Nzk4ODQsImV4cCI6MTkwODgzOTg4NCwibmJmIjoxNTkzNDc5ODg0LCJqdGkiOiI3TzFCVHkxT1VlWkNnaTFmIiwib3BlbklkIjoib1JFNXIxS001ejkyOFRQRXY5LXVTZm1nSkpXQSIsIndlY2hhdF9pZCI6Im9SRTVyMUtNNXo5MjhUUEV2OS11U2ZtZ0pKV0EiLCJ1bmlvbmlkIjoib3EySG8xWlJqOENUMmxsQlpONkNqbHJEZ19TSSIsImdvbmd6aG9uZyI6InpodWtlYmFvIn0.jzFyB7yrrFueRO-UkWPQKZqa4JPdXQZYA1KkwIQt5xg',
'appVersion':'1.0.7',
'osVersion':'10',
'jsVersion':'',
'appName':'??',
'deviceModel':'MI 8',
'deviceId':'',
'platform':'android',
'user-agent': 'MI 8(Android/10) (???/1.0.7) Weex/0.18.0 1080x2115',
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'Host': 'tiku.xuexibao.tech',
'Connection': 'Keep-Alive',
'Accept-Encoding': 'gzip'
}
data = {
'goods_id':'6116',
'index':'0',
'content':keyword,
'sign':'6fc87ae8bd7b2cdd95ac3cbafe50885503ceceed'
}
req = requests.post(url,headers=headers,data=data,timeout=20).json()
answers = ''
for i in range (0,len(req['data'])):
question = req['data'][i]['question']
answer = req['data'][i]['answer']
answers = answers + '题目:'+question + '\n' +'答案:'+ answer +'\n\n'
self.编辑框4.insert(tk.END,'接口1:\n')
self.编辑框4.insert(tk.END,answers)
except:
self.编辑框4.insert(tk.END,'接口1:\n')
self.编辑框4.insert(tk.END,'查题失败\n')
##########接口二#########
try:
url = 'http://api.xmlm8.com/'
data = {
'w':keyword
}
req = requests.post(url,data=data,timeout=20)
html = etree.HTML(req.text)
t = html.xpath('/html/body/div[2]/span[1]/text()')[0]
a = html.xpath('/html/body/div[2]/span[2]/text()')[0]
answers = t + '\n' + a +'\n\n'
self.编辑框4.insert(tk.END,'接口2:\n')
self.编辑框4.insert(tk.END,answers)
except:
self.编辑框4.insert(tk.END,'接口2:\n')
except:
self.编辑框4.insert(tk.END,'查题失败,可能接口已失效')
if __name__ == '__main__':
root = tk.Tk()
root.attributes("-alpha",1)
root.attributes("-topmost", True)
app = PyWinDesign(root)
root.mainloop()