您好,登錄后才能下訂單哦!
博主爬取了扇貝英語網,并制作了一個英語單詞測試的小程序,還能生成錯詞本,一起來看下代碼吧~
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。