Update 'ScrapeJE.py'
This commit is contained in:
69
ScrapeJE.py
Normal file
69
ScrapeJE.py
Normal file
@@ -0,0 +1,69 @@
|
||||
#lo script scrapa 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
|
||||
|
||||
nome=[]
|
||||
desc=[]
|
||||
npezzi=[]
|
||||
prezzo=[]
|
||||
|
||||
#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"})
|
||||
|
||||
#Stampa nome ristorante
|
||||
print("\nRISTORANTE:",soup.title.text)
|
||||
|
||||
# alla riga 870 dell html c'è "allergenPhoneNumber":"3389529446"
|
||||
|
||||
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])
|
||||
else:
|
||||
desc.append(None)
|
||||
|
||||
#riempie la lista "prezzo"
|
||||
for att in menu.find("p", class_="c-menuItems-price notranslate"):
|
||||
prezzo.append(att.lstrip().splitlines()[0])
|
||||
|
||||
#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:
|
||||
npezzi.append(menu.text.splitlines()[7].lstrip())
|
||||
else:
|
||||
npezzi.append(None)
|
||||
continue
|
||||
|
||||
#stampa liste
|
||||
for x in range(len(nome)):
|
||||
print("\n")
|
||||
print(nome[x])
|
||||
print(desc[x])
|
||||
print(npezzi[x])
|
||||
print(prezzo[x])
|
||||
|
||||
#stampa lunghezza liste
|
||||
print("\nlista nomi:",len(nome))
|
||||
print("lista desc:",len(desc))
|
||||
print("lista npezzi:",len(npezzi))
|
||||
print("lista prezzi:",len(prezzo))
|
||||
Reference in New Issue
Block a user