1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import requests
import re
import os
caches = (
dict(
moteur='google',
fichier='./google_cache_forge-metaux-outil-support',
url='https://www.google.fr/search?q=forge+métaux+support',
),
dict(
moteur='duckduckgo',
fichier='./duckduckgo_cache_forge-metaux-outil-support',
url='https://duckduckgo.com/html?q=forge+métaux+outil+support&kl=fr-fr',
),
)
# Mise en cache pour travailler sur des copies locales
for item in caches :
if not os.path.isfile(item['fichier']) :
req = requests.get(item['url'])
html = req.text
with open(item['fichier'], 'w') as f :
f.write(html)
for item in caches :
with open(item['fichier']) as f :
print('#' * 10, item['moteur'], '#' * 10)
html = f.read()
for s in ('enclume', 'acier', 'patine') :
print(s, len(re.findall('\W({})\W'.format(s), html, flags=re.I))) |
Partager