Update 'BozzaScrapeJE.py'
This commit is contained in:
@@ -4,62 +4,57 @@ import cloudscraper
|
|||||||
|
|
||||||
nome=[]
|
nome=[]
|
||||||
desc=[]
|
desc=[]
|
||||||
desc2=[]
|
npezzi=[]
|
||||||
prezzo=[]
|
prezzo=[]
|
||||||
n=0
|
n=0
|
||||||
|
|
||||||
#scrape html
|
#scrape html
|
||||||
scraper = cloudscraper.create_scraper(browser={'browser': 'firefox','platform': 'windows','mobile': False})
|
# scraper = cloudscraper.create_scraper(browser={'browser': 'firefox','platform': 'windows','mobile': False})
|
||||||
page = scraper.get("https://www.justeat.it/restaurants-saporedialeppo/menu").content
|
# page = scraper.get("https://www.justeat.it/restaurants-saporedialeppo/menu").content
|
||||||
with open('aleppo.html', 'wb') as f:
|
# with open('aleppo.html', 'wb') as f:
|
||||||
f.write(page)
|
# f.write(page)
|
||||||
|
|
||||||
with open('aleppo.html', 'rb') as f:
|
with open('aleppo.html', 'rb') as f:
|
||||||
page = f.read()
|
page = f.read()
|
||||||
|
|
||||||
soup = BeautifulSoup(page, "html.parser")
|
soup = BeautifulSoup(page, "html.parser")
|
||||||
menu = soup.find(attrs={"data-test-id": "menu-item-name"})
|
menu = soup.find(attrs={"data-test-id": "menu-item"})
|
||||||
|
|
||||||
#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"}):
|
||||||
for menu in soup.find_all(attrs={"data-test-id": "menu-item-description"}):
|
att=menu
|
||||||
if menu.text.find("pezza") > 0: #poichè c'è un piatto con lo sPEZZAtino
|
|
||||||
desc.append(menu.text.splitlines()[1])
|
#riempie la lista "nome"
|
||||||
desc[n]=desc[n].lstrip()
|
for att in menu.find(attrs={"data-test-id": "menu-item-name"}):
|
||||||
desc2.append("")
|
if att != " ":
|
||||||
n=n+1
|
nome.append(att.lstrip().splitlines()[0])
|
||||||
elif menu.text.find("pezz") > 0:
|
|
||||||
desc2.append(menu.text.splitlines()[1])
|
#riempie la lista "desc"
|
||||||
desc2[n]=desc2[n].lstrip()
|
att=menu.find("p", class_="c-menuItems-description")
|
||||||
desc.append("")
|
if att != None:
|
||||||
n=n+1
|
for att in menu.find("p", class_="c-menuItems-description"):
|
||||||
|
desc.append(att.lstrip().splitlines()[0])
|
||||||
else:
|
else:
|
||||||
desc.append(menu.text.splitlines()[1])
|
desc.append(None)
|
||||||
desc[n]=desc[n].lstrip()
|
|
||||||
desc2.append("")
|
|
||||||
n=n+1
|
|
||||||
n=0
|
|
||||||
|
|
||||||
#riempie la lista "prezzo" con le descrizioni dei prodotti
|
# #riempie la lista "npezzi"
|
||||||
for menu in soup.find_all(class_="c-menuItems-price notranslate"):
|
# for att in menu.find_next(attrs={"data-test-id": "menu-item-description"}):
|
||||||
prezzo.append(menu.text.splitlines()[1])
|
# npezzi.append(att.lstrip().splitlines()[0])
|
||||||
prezzo[n]=prezzo[n].lstrip()
|
|
||||||
n=n+1
|
|
||||||
n=0
|
|
||||||
|
|
||||||
|
#riempie la lista "prezzo"
|
||||||
|
for att in menu.find("p", class_="c-menuItems-price notranslate"):
|
||||||
|
prezzo.append(att.lstrip().splitlines()[0])
|
||||||
|
|
||||||
|
#stampa liste
|
||||||
for x in range(len(nome)):
|
for x in range(len(nome)):
|
||||||
|
print("\n")
|
||||||
print(nome[x])
|
print(nome[x])
|
||||||
print(desc[x])
|
print(desc[x])
|
||||||
print(desc2[x])
|
# print(npezzi[x])
|
||||||
print(prezzo[x],"\n")
|
print(prezzo[x])
|
||||||
|
|
||||||
print(len(nome))
|
#stampa lunghezza liste
|
||||||
print(len(desc))
|
print("\nlista nomi:",len(nome))
|
||||||
print(len(desc2))
|
print("lista desc:",len(desc))
|
||||||
print(len(prezzo))
|
print("lista npezzi:",len(npezzi))
|
||||||
|
print("lista prezzi:",len(prezzo))
|
||||||
|
|||||||
Reference in New Issue
Block a user