Look only for French dictionary entries

This commit is contained in:
Benjamin Loison 2024-04-01 01:22:10 +02:00
parent a39d22ab72
commit c90beee5fc
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

19
main.py
View File

@ -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('')