2022-09-27 18:47:25 +02:00
|
|
|
import requests
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
import cloudscraper
|
|
|
|
|
|
|
|
|
|
nome=[]
|
|
|
|
|
desc=[]
|
2022-09-29 19:07:26 +02:00
|
|
|
npezzi=[]
|
2022-09-27 18:47:25 +02:00
|
|
|
prezzo=[]
|
|
|
|
|
n=0
|
|
|
|
|
|
|
|
|
|
#scrape html
|
2022-09-29 19:07:26 +02:00
|
|
|
# scraper = cloudscraper.create_scraper(browser={'browser': 'firefox','platform': 'windows','mobile': False})
|
|
|
|
|
# page = scraper.get("https://www.justeat.it/restaurants-saporedialeppo/menu").content
|
|
|
|
|
# with open('aleppo.html', 'wb') as f:
|
|
|
|
|
# f.write(page)
|
2022-09-27 18:47:25 +02:00
|
|
|
|
|
|
|
|
with open('aleppo.html', 'rb') as f:
|
|
|
|
|
page = f.read()
|
|
|
|
|
|
|
|
|
|
soup = BeautifulSoup(page, "html.parser")
|
2022-09-29 19:07:26 +02:00
|
|
|
menu = soup.find(attrs={"data-test-id": "menu-item"})
|
2022-09-27 18:47:25 +02:00
|
|
|
|
2022-09-30 23:27:10 +02:00
|
|
|
#Stampa nome ristorante
|
|
|
|
|
print("\nRISTORANTE:",soup.title.text)
|
|
|
|
|
|
|
|
|
|
# alla riga 870 dell html c'รจ "allergenPhoneNumber":"3389529446"
|
2022-09-27 18:47:25 +02:00
|
|
|
|
2022-09-29 19:07:26 +02:00
|
|
|
for menu in soup.find_all(attrs={"data-test-id": "menu-item"}):
|
|
|
|
|
att=menu
|
|
|
|
|
#riempie la lista "nome"
|
|
|
|
|
for att in menu.find(attrs={"data-test-id": "menu-item-name"}):
|
|
|
|
|
if att != " ":
|
|
|
|
|
nome.append(att.lstrip().splitlines()[0])
|
|
|
|
|
|
|
|
|
|
#riempie la lista "desc"
|
|
|
|
|
att=menu.find("p", class_="c-menuItems-description")
|
|
|
|
|
if att != None:
|
|
|
|
|
for att in menu.find("p", class_="c-menuItems-description"):
|
|
|
|
|
desc.append(att.lstrip().splitlines()[0])
|
2022-09-27 18:47:25 +02:00
|
|
|
else:
|
2022-09-29 19:07:26 +02:00
|
|
|
desc.append(None)
|
2022-09-27 18:47:25 +02:00
|
|
|
|
2022-09-29 19:07:26 +02:00
|
|
|
#riempie la lista "prezzo"
|
|
|
|
|
for att in menu.find("p", class_="c-menuItems-price notranslate"):
|
|
|
|
|
prezzo.append(att.lstrip().splitlines()[0])
|
2022-09-27 18:47:25 +02:00
|
|
|
|
2022-09-30 23:27:40 +02:00
|
|
|
#riempie la lista "npezzi"
|
2022-09-30 23:27:10 +02:00
|
|
|
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:
|
|
|
|
|
npezzi.append(menu.text.splitlines()[7].lstrip())
|
|
|
|
|
else:
|
|
|
|
|
npezzi.append(None)
|
|
|
|
|
continue
|
|
|
|
|
|
2022-09-29 19:07:26 +02:00
|
|
|
#stampa liste
|
2022-09-27 18:47:25 +02:00
|
|
|
for x in range(len(nome)):
|
2022-09-30 23:27:10 +02:00
|
|
|
print("\n")
|
|
|
|
|
print(nome[x])
|
|
|
|
|
print(desc[x])
|
|
|
|
|
print(npezzi[x])
|
|
|
|
|
print(prezzo[x])
|
2022-09-29 19:07:26 +02:00
|
|
|
|
|
|
|
|
#stampa lunghezza liste
|
|
|
|
|
print("\nlista nomi:",len(nome))
|
|
|
|
|
print("lista desc:",len(desc))
|
|
|
|
|
print("lista npezzi:",len(npezzi))
|
2022-09-30 23:27:10 +02:00
|
|
|
print("lista prezzi:",len(prezzo))
|