mirror of
https://github.com/guezoloic/millesima_projetS6.git
synced 2026-03-28 19:13:42 +00:00
ajout(main.py): ajout dans csv
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -205,3 +205,5 @@ cython_debug/
|
|||||||
marimo/_static/
|
marimo/_static/
|
||||||
marimo/_lsp/
|
marimo/_lsp/
|
||||||
__marimo__/
|
__marimo__/
|
||||||
|
|
||||||
|
*.csv
|
||||||
41
main.py
41
main.py
@@ -299,31 +299,34 @@ class Scraper:
|
|||||||
except JSONDecodeError | HTTPError:
|
except JSONDecodeError | HTTPError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getvins(self, subdir: str):
|
def getvins(self, subdir: str, filename: str):
|
||||||
cache: set[str] = set[str]()
|
cache: set[str] = set[str]()
|
||||||
page = 0
|
page = 0
|
||||||
|
|
||||||
while True:
|
with open(filename, 'a') as f:
|
||||||
page += 1
|
while True:
|
||||||
products_list = self._geturlproductslist(f"{subdir}?page={page}")
|
page += 1
|
||||||
|
products_list = self._geturlproductslist(f"{subdir}?page={page}")
|
||||||
|
|
||||||
print(f"---- {page} ----")
|
print(f"---- {page} ----")
|
||||||
if not products_list:
|
if not products_list:
|
||||||
break
|
break
|
||||||
|
|
||||||
for product in products_list:
|
for product in products_list:
|
||||||
if not isinstance(product, dict):
|
if not isinstance(product, dict):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
link = product.get("seoKeyword")
|
link = product.get("seoKeyword")
|
||||||
|
|
||||||
if link and link not in cache:
|
if link and link not in cache:
|
||||||
try:
|
try:
|
||||||
infos = self.getjsondata(link).informations()
|
infos = self.getjsondata(link).informations()
|
||||||
print(infos)
|
_ = f.write(infos + "\n")
|
||||||
cache.add(link)
|
print(infos)
|
||||||
except JSONDecodeError | HTTPError as e:
|
cache.add(link)
|
||||||
print(f"Erreur sur le produit {link}: {e}")
|
except JSONDecodeError | HTTPError as e:
|
||||||
|
print(f"Erreur sur le produit {link}: {e}")
|
||||||
|
f.flush()
|
||||||
|
|
||||||
|
|
||||||
# Scraper().getvins("bordeaux.html")
|
Scraper().getvins("bordeaux.html", "donnee.csv")
|
||||||
|
|||||||
Reference in New Issue
Block a user