forked from urassh/Words-Test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (32 loc) · 1.02 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from QuizFunction import Quiz
import random
import requests
import re
from bs4 import BeautifulSoup
url = 'https://toiguru.jp/toeic-vocabulary-list#smoothplay1'
encord_english = []
english = []
japanese = []
try:
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')
words = soup.findAll('td')
except requests.exceptions.ConnectionError as e:
print("※URLが正しくありません。")
print(e)
else:
print("requests Succefull")
for word in words:
word = str(word).replace('<td>', '').replace('</td>', '').replace('<br/>', '')
encord_english.append(re.findall('[a-z]+', word))
japanese.append(re.sub("[a-zA-Z]", "", word))
for words in encord_english:
english.append(' '.join(words))
if len(english) == len(japanese):
print("単語を取得しました。")
else:
print("単語の取得に失敗しました。")
questions = dict(zip(english, japanese))
quiz = Quiz(questions)
result = quiz.quiz_handler()
print(result)