-
Notifications
You must be signed in to change notification settings - Fork 1
/
wordlist.py
64 lines (44 loc) · 1.23 KB
/
wordlist.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
"""
explore word list from duolingo inspect element
Created on Thu Aug 31 09:13:00 2017
@author: HanchaMS
"""
from bs4 import BeautifulSoup as soup
with open("wordlist2.txt") as f:
htmlcode = f.read()
souped = soup(htmlcode, "html.parser")
'''
containers = souped.findAll("span",{"class":"hoverable-word hover"})
for container in containers:
print(container.text)
containers = souped.findAll('span',{'class':'hover'})
with open("words.csv", 'w') as f:
for container in containers:
f.write(container.text + '\n')
'''
parts = (
'Adjective',
'Adverb',
'Conjunction',
'Determiner',
'Interjection',
'Noun',
'Numeral',
'Preposition',
'Pronoun',
'Proper noun',
'Verb')
temp = souped.findAll('td')
with open("words2.txt", 'w') as f:
for i,q in enumerate(temp):
try:
# try to print the word and the part of speech (usually one later)
f.write(q['data-string'])
w = temp[i+1].text
if w in parts:
f.write(',' + w + '\n')
else:
f.write(',\n')
except:
pass