Update 'ScrapeJE.py'
This commit is contained in:
17
ScrapeJE.py
17
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))
|
||||
Reference in New Issue
Block a user