Look only for French dictionary entries
This commit is contained in:
parent
a39d22ab72
commit
c90beee5fc
19
main.py
19
main.py
@ -13,21 +13,24 @@ MAXIMUM_SUGGESTIONS = 4
|
||||
entries = set()
|
||||
|
||||
def treatSuffixes(prefix):
|
||||
print(prefix)
|
||||
#print(prefix)
|
||||
for char in charset:
|
||||
base = prefix + char
|
||||
print(base)
|
||||
params['qe'] = base
|
||||
text = requests.get(url, params = params).text
|
||||
tree = html.fromstring(text)
|
||||
items = tree.xpath('//div[@class="main_item"]')
|
||||
itemsLen = len(items)
|
||||
assert itemsLen <= MAXIMUM_SUGGESTIONS, f'More than {MAXIMUM_SUGGESTIONS} items!'
|
||||
for item in items:
|
||||
rows = tree.xpath('//div[@class="main_row"]')
|
||||
rowsLen = len(rows)
|
||||
assert rowsLen <= MAXIMUM_SUGGESTIONS, f'More than {MAXIMUM_SUGGESTIONS} rows!'
|
||||
for row in rows:
|
||||
item = row.xpath('div[@class="main_item"]')[0]
|
||||
entry = item.text_content()
|
||||
if not entry in entries:
|
||||
print(len(entries), entry)
|
||||
wordType = row.xpath('div[@class="main_wordtype"]')
|
||||
if wordType != [] and item.attrib['lc'] == 'FR' and not entry in entries:
|
||||
print(len(entries), entry, wordType[0].text_content())
|
||||
entries.add(entry)
|
||||
if itemsLen == MAXIMUM_SUGGESTIONS:
|
||||
if rowsLen == MAXIMUM_SUGGESTIONS:
|
||||
treatSuffixes(base)
|
||||
|
||||
treatSuffixes('')
|
Loading…
Reference in New Issue
Block a user