您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
博主爬取了扇贝英语网,并制作了一个英语单词测试的小程序,还能生成错词本,一起来看下代码吧~
import requests
#扇贝网爬虫,获取英语单词
category_res=requests.get('https://www.shanbay.com/api/v1/vocabtest/category/?_=1566889802182')
category_json=category_res.json()
category_data=category_json['data']
#选择出题范围
for i in range(10):
print(str(i+1)+'.'+category_data[i][1])
number=int(input('请选择出题范围:'))
url='https://www.shanbay.com/api/v1/vocabtest/vocabularies/'
headers={
'Referer': 'https://www.shanbay.com/vocabtest/',
}
params={
'category':category_data[number-1][0],
'_': '1566889452889'
}
res=requests.get(url,headers=headers,params=params)
jsonres=res.json()
vacabularies=jsonres['data']
knows=[]
unknows=[]
print()
print('以下单词你是否认识?')
n=0
z=0
b=open('错词本.txt','a+')
b.write('你不认识的单词有:\n')
#测试开始,挑选认识的单词
for vacabulary in vacabularies:
n=n+1
vacabu=vacabulary['content']
print('第'+str(n)+'个:'+vacabu)
index=vacabularies.index(vacabulary)
while True:
judge=input('认识选Y,不认识选N:')
if judge=='Y':
knows.append(index)
break
elif judge=='N':
unknows.append(index)
z=z+1
b.write(str(z)+'.'+vacabu+'\n')
break
else:
print('请输入Y或者N')
print()
print('测试结束,以下是测试结果:')
print('认识'+str(len(knows))+'个单词,不认识'+str(len(unknows))+'个单词。')
print('你可真棒!')
print()
right=[]
wrong=[]
#选择正确的词义
b.write('你记错的单词有:\n')
m=0
for know in knows:
vacabulary_know=vacabularies[know]
word=vacabulary_know['content']
print()
print(word)
definitions=vacabulary_know['definition_choices']
for i in range(4):
print(str(i+1)+'.'+definitions[i]['definition'])
choice=int(input('单词测试,请选择正确的词义:'))
rank=definitions[choice-1]['rank']
if rank==vacabulary_know['rank']:
right.append(word)
else:
wrong.append(word)
m=m+1
b.write(str(m)+'.'+word+'\n')
print()
print('测试结果出来啦!')
print('认识的单词里掌握了这几个:')
print(right)
print()
print('没掌握的是这几个:')
print(wrong)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。