65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
|
|
import requests
|
||
|
|
from bs4 import BeautifulSoup
|
||
|
|
import cloudscraper
|
||
|
|
|
||
|
|
nome=[]
|
||
|
|
desc=[]
|
||
|
|
desc2=[]
|
||
|
|
prezzo=[]
|
||
|
|
n=0
|
||
|
|
|
||
|
|
#scrape html
|
||
|
|
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)
|
||
|
|
|
||
|
|
with open('aleppo.html', 'rb') as f:
|
||
|
|
page = f.read()
|
||
|
|
|
||
|
|
soup = BeautifulSoup(page, "html.parser")
|
||
|
|
menu = soup.find(attrs={"data-test-id": "menu-item-name"})
|
||
|
|
|
||
|
|
#riempie la lista "nome" con i nomi dei prodotti
|
||
|
|
for menu in soup.find_all(attrs={"data-test-id": "menu-item-name"}):
|
||
|
|
nome.append(menu.text.splitlines()[2])
|
||
|
|
nome[n]=nome[n].lstrip()
|
||
|
|
n=n+1
|
||
|
|
n=0
|
||
|
|
|
||
|
|
#riempie la lista "desc" con le descrizioni dei prodotti
|
||
|
|
for menu in soup.find_all(attrs={"data-test-id": "menu-item-description"}):
|
||
|
|
if menu.text.find("pezza") > 0: #poichè c'è un piatto con lo sPEZZAtino
|
||
|
|
desc.append(menu.text.splitlines()[1])
|
||
|
|
desc[n]=desc[n].lstrip()
|
||
|
|
desc2.append("")
|
||
|
|
n=n+1
|
||
|
|
elif menu.text.find("pezz") > 0:
|
||
|
|
desc2.append(menu.text.splitlines()[1])
|
||
|
|
desc2[n]=desc2[n].lstrip()
|
||
|
|
desc.append("")
|
||
|
|
n=n+1
|
||
|
|
else:
|
||
|
|
desc.append(menu.text.splitlines()[1])
|
||
|
|
desc[n]=desc[n].lstrip()
|
||
|
|
desc2.append("")
|
||
|
|
n=n+1
|
||
|
|
n=0
|
||
|
|
|
||
|
|
#riempie la lista "prezzo" con le descrizioni dei prodotti
|
||
|
|
for menu in soup.find_all(class_="c-menuItems-price notranslate"):
|
||
|
|
prezzo.append(menu.text.splitlines()[1])
|
||
|
|
prezzo[n]=prezzo[n].lstrip()
|
||
|
|
n=n+1
|
||
|
|
n=0
|
||
|
|
|
||
|
|
for x in range(len(nome)):
|
||
|
|
print(nome[x])
|
||
|
|
print(desc[x])
|
||
|
|
print(desc2[x])
|
||
|
|
print(prezzo[x],"\n")
|
||
|
|
|
||
|
|
print(len(nome))
|
||
|
|
print(len(desc))
|
||
|
|
print(len(desc2))
|
||
|
|
print(len(prezzo))
|