First recursive enumeration try
This commit is contained in:
parent
8d0a889a0f
commit
a39d22ab72
26
main.py
26
main.py
@ -1,15 +1,33 @@
|
||||
import requests
|
||||
from lxml import html
|
||||
import string
|
||||
|
||||
charset = string.ascii_lowercase
|
||||
url = 'https://www.linguee.fr/francais-anglais/search'
|
||||
params = {
|
||||
'qe': 'a',
|
||||
'ch': 0
|
||||
}
|
||||
|
||||
MAXIMUM_SUGGESTIONS = 4
|
||||
|
||||
entries = set()
|
||||
|
||||
def treatSuffixes(prefix):
|
||||
print(prefix)
|
||||
for char in charset:
|
||||
base = prefix + char
|
||||
params['qe'] = base
|
||||
text = requests.get(url, params = params).text
|
||||
#print(text)
|
||||
tree = html.fromstring(text)
|
||||
items = tree.xpath('//div[@class="main_item"]')
|
||||
#print(len(items))
|
||||
itemsLen = len(items)
|
||||
assert itemsLen <= MAXIMUM_SUGGESTIONS, f'More than {MAXIMUM_SUGGESTIONS} items!'
|
||||
for item in items:
|
||||
print(item.text_content())
|
||||
entry = item.text_content()
|
||||
if not entry in entries:
|
||||
print(len(entries), entry)
|
||||
entries.add(entry)
|
||||
if itemsLen == MAXIMUM_SUGGESTIONS:
|
||||
treatSuffixes(base)
|
||||
|
||||
treatSuffixes('')
|
Loading…
Reference in New Issue
Block a user