From c90beee5fc5dd9dc5c78e659133e6775b0d6a468 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Mon, 1 Apr 2024 01:22:10 +0200 Subject: [PATCH] Look only for French dictionary entries --- main.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 43b9906..1b1e594 100644 --- a/main.py +++ b/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) - entries.add(entry) - if itemsLen == MAXIMUM_SUGGESTIONS: + 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 rowsLen == MAXIMUM_SUGGESTIONS: treatSuffixes(base) treatSuffixes('') \ No newline at end of file