-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
50 lines (32 loc) · 1.12 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
41
42
43
44
45
46
47
48
49
50
from QuizFunction import Quiz
import random
import requests
import re
from bs4 import BeautifulSoup
url = 'https://toiguru.jp/toeic-vocabulary-list#smoothplay1'
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/>', '')
english.append(re.findall('[a-z]+', word))
japanese.append(re.sub("[a-zA-Z]", "", word))
if len(english) == len(japanese):
print("単語を取得しました。")
else:
print("単語の取得に失敗しました。")
#englishリストが、二重リストになっていて、[be], [interested], [in]という状態を解消する。
# questions = dict(zip(english, japanese))
# for s, t in enumerate(questions):
# print(f'{s} : {t}')
# quiz = Quiz(questions)
# result = quiz.quiz_handler()
# print(result)