From fca2788dd47cd8c584074594067589904b22c16f Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Mon, 1 Apr 2024 01:41:09 +0200 Subject: [PATCH] Limit recursion to `base` having a word type having the original `base` in it --- main.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 1b1e594..adbc6c7 100644 --- a/main.py +++ b/main.py @@ -19,18 +19,25 @@ def treatSuffixes(prefix): print(base) params['qe'] = base text = requests.get(url, params = params).text + # Pay attention if change `base` elaboration to not allow unwanted folder file writing. + with open(f'requests/{base}.html', 'w') as requestFile: + requestFile.write(text) tree = html.fromstring(text) rows = tree.xpath('//div[@class="main_row"]') rowsLen = len(rows) assert rowsLen <= MAXIMUM_SUGGESTIONS, f'More than {MAXIMUM_SUGGESTIONS} rows!' + interestingEntries = True for row in rows: item = row.xpath('div[@class="main_item"]')[0] entry = item.text_content() 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: + if wordType != []: + if item.attrib['lc'] == 'FR' and not entry in entries: + print(len(entries), entry, wordType[0].text_content()) + entries.add(entry) + if not base in entry: + interestingEntries = False + if rowsLen == MAXIMUM_SUGGESTIONS and interestingEntries: treatSuffixes(base) treatSuffixes('') \ No newline at end of file