First recursive enumeration try

This commit is contained in:
Benjamin Loison 2024-04-01 01:09:42 +02:00
parent 8d0a889a0f
commit a39d22ab72
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

34
main.py
View File

@ -1,15 +1,33 @@
import requests import requests
from lxml import html from lxml import html
import string
charset = string.ascii_lowercase
url = 'https://www.linguee.fr/francais-anglais/search' url = 'https://www.linguee.fr/francais-anglais/search'
params = { params = {
'qe': 'a',
'ch': 0 'ch': 0
} }
text = requests.get(url, params = params).text
#print(text) MAXIMUM_SUGGESTIONS = 4
tree = html.fromstring(text)
items = tree.xpath('//div[@class="main_item"]') entries = set()
#print(len(items))
for item in items: def treatSuffixes(prefix):
print(item.text_content()) print(prefix)
for char in charset:
base = prefix + char
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:
entry = item.text_content()
if not entry in entries:
print(len(entries), entry)
entries.add(entry)
if itemsLen == MAXIMUM_SUGGESTIONS:
treatSuffixes(base)
treatSuffixes('')