Python学习-扇贝英语单词测试,主要学习requests

爬虫扇贝网英语测评页面

import requests
url = 'https://www.shanbay.com/api/v1/vocabtest/category/'
res = requests.get(url)
print(res)
json_res = res.json()
words_knows=[]
not_knows = []
words = {}
answers = {}
zw = 0
cw = 0
print('词库选择:')
num = 1
num2 = 1
for data in json_res['data']:
    print(str(num) +'-'+data[1])
    words[num] = data[0]
    num += 1
print('请选择想测的词库,输入序号即可:')
while True:
    try:
        choose = int(input(''))
        if 1<=choose<=10:
            category = words[choose]
            break
        else:
            print('请输入正确的词库序号:')     
    except ValueError:
        print('请输入正确的词库序号:')
url2 = 'https://www.shanbay.com/api/v1/vocabtest/vocabularies/'
params = {'category': category }
res2 = requests.get(url2,params=params)
json_res2 = res2.json()
print('好的,接下来请你选择认识的单词:')
for word in json_res2['data']:
    uword = word['content']
    knows = input(uword+'--这个单词你认识吗?认识输入任意键,不认识直接回车:\n')
    if knows != '':
        words_knows.append(uword)
        print('请选择【',uword,'】的正确词义:') 
        for answer in word['definition_choices']:
            answers[num2] = [answer['pk'],answer['rank']]
            print(str(num2),'-',answer['definition'])
            num2+=1
        print('5-不认识')
        while True:
            try:
                chooses = int(input(''))
            
                if 1<=chooses<=4:
                    if word['pk'] == answers[chooses][0] and word['rank'] == answers[chooses][1]:
                        print('回答正确')
                        zw +=1
                    else:
                        print('回答错误')
                        cw +=1
                    break
                elif chooses == 5:
                    words_knows.remove(uword)
                    not_knows.append(uword)
                    break
                else:
                    print('请输入正确的序号:')     
            except ValueError:
                print('请输入正确的序号:')

    else:
        not_knows.append(uword)
    num2 = 1     


print('认识{}个单词,不认识{}个单词,掌握{}个,做错了{}个'.format(len(words_knows),len(not_knows),zw,cw))
温馨提示:本文最后更新于2021-10-16 22:04:20
某些文章具有时效性,若有错误或已失效,请在下方留言或联系PING科技-站长
© 版权声明
THE END
喜欢就支持以下吧
点赞0
分享
评论 抢沙发
Ping科技的头像-Ping科技/iOS黑科技资源网

昵称

取消
昵称表情代码图片