From 96b7a02aa4e89098558ce2da55de0ce605429802 Mon Sep 17 00:00:00 2001 From: scossa Date: Sat, 1 Oct 2022 00:22:45 +0200 Subject: [PATCH] Update 'ScrapeJE.py' --- ScrapeJE.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ScrapeJE.py b/ScrapeJE.py index cd672a1..e278eac 100644 --- a/ScrapeJE.py +++ b/ScrapeJE.py @@ -1,5 +1,3 @@ -#lo script scrapa e stora in 4 liste il nome dei prodotti, la descrizione (se c'è), la quantità dei pezzi (se specificato) e il prezzo. - import requests from bs4 import BeautifulSoup import cloudscraper @@ -8,6 +6,7 @@ nome=[] desc=[] npezzi=[] prezzo=[] +n=0 #scrape html # scraper = cloudscraper.create_scraper(browser={'browser': 'firefox','platform': 'windows','mobile': False}) @@ -21,8 +20,10 @@ with open('aleppo.html', 'rb') as f: soup = BeautifulSoup(page, "html.parser") menu = soup.find(attrs={"data-test-id": "menu-item"}) -#Stampa nome ristorante -print("\nRISTORANTE:",soup.title.text) + +#Stora nome ristorante +nrist=soup.title.text[8:24] +menu.find(attrs={"allergenPhoneNumber": "menu-item-name"}) # alla riga 870 dell html c'è "allergenPhoneNumber":"3389529446" @@ -45,7 +46,7 @@ for menu in soup.find_all(attrs={"data-test-id": "menu-item"}): for att in menu.find("p", class_="c-menuItems-price notranslate"): prezzo.append(att.lstrip().splitlines()[0]) - #riempie la lista "npezzi" + # #riempie la lista "npezzi" att=menu.find_all(attrs={"data-test-id": "menu-item-description"}) if att != None: if menu.text.find("pezzo") > 0 or menu.text.find("pezzi") > 0: @@ -62,8 +63,10 @@ for x in range(len(nome)): print(npezzi[x]) print(prezzo[x]) -#stampa lunghezza liste -print("\nlista nomi:",len(nome)) +#stampa lunghezza liste del risrorante +print("\n") +print(nrist) +print("lista nome",len(nome),) print("lista desc:",len(desc)) print("lista npezzi:",len(npezzi)) print("lista prezzi:",len(prezzo)) \ No newline at end of file