博主爬取了扇贝英语网,并制作了一个英语单词测试的小程序,还能生成错词本,一起来看下代码吧~
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/‘,‘User-Agent‘: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML,like Gecko) Version/12.1 Safari/605.1.15‘ } 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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。