Vergleich der Auswahl an Gerichten von drei Restaurants in St. Petersburg

Ich musste mich noch nie mit dem Parsen von Daten aus dem Internet befassen. Normalerweise stammen alle Daten für die Arbeit (Datenanalyst) aus den Entladungen des Unternehmens über eine einfache interne Schnittstelle oder werden durch SQL-Abfragen an Tabellen direkt aus dem Speicher gebildet, wenn Sie etwas Komplexeres benötigen als „Sehen Sie sich die Einnahmen für die vorherigen an Monat". 





Daher wollte ich ein einfaches Tool zum Parsen von HTML-Seiten beherrschen, um Daten aus dem Internet mithilfe von Code in einer praktischen IDE erfassen zu können, ohne Tools von Drittanbietern zu verwenden. 





Die Standorte für die Datenerfassung wurden nach dem Prinzip „Es gibt keinen Parserblocker“ ausgewählt und „aus der Analyse dieser Daten kann etwas Interessantes entstehen“. Daher fiel die Auswahl auf eine Auswahl an Gerichten für die Lieferung von drei Restaurants in St. Petersburg - "Tokyo City", "Eurasia" und "2 Berega". Sie haben ungefähr den gleichen Küchenfokus und ein ähnliches Sortiment, so dass es eindeutig etwas zu vergleichen gibt. 





Ich werde den Parser selbst für eines der Restaurants teilen.





import requests
from bs4 import BeautifulSoup
import pandas as pd
import datetime

print("   : " + str(datetime.datetime.now()))
#     
urllist = ['https://www.tokyo-city.ru/spisok-product/goryachie-blyuda1.html',
           'https://www.tokyo-city.ru/spisok-product/sushi.html',
           'https://www.tokyo-city.ru/spisok-product/rolly.html',
           'https://www.tokyo-city.ru/spisok-product/nabory.html',
           'https://www.tokyo-city.ru/spisok-product/new_lunches.html',
           'https://www.tokyo-city.ru/spisok-product/pitctca.html',
           'https://www.tokyo-city.ru/spisok-product/salaty.html',
           'https://www.tokyo-city.ru/spisok-product/-supy-.html',
           'https://www.tokyo-city.ru/spisok-product/goryachie-zakuski1.html',
           'https://www.tokyo-city.ru/spisok-product/wok.html',
           'https://www.tokyo-city.ru/spisok-product/pasta.html',
           'https://www.tokyo-city.ru/spisok-product/gamburgery-i-shaverma.html',
           'https://www.tokyo-city.ru/spisok-product/Tokio-FIT.html',
           'https://www.tokyo-city.ru/spisok-product/deserty.html',
           'https://www.tokyo-city.ru/spisok-product/childrensmenu.html',
           'https://www.tokyo-city.ru/spisok-product/napitki1.html',
           'https://www.tokyo-city.ru/new/',
           'https://www.tokyo-city.ru/spisok-product/postnoe-menyu.html',
           'https://www.tokyo-city.ru/hit/',
           'https://www.tokyo-city.ru/vegetarian/',
           'https://www.tokyo-city.ru/hot/',
           'https://www.tokyo-city.ru/offers/',
           'https://www.tokyo-city.ru/spisok-product/sauces.html',
           'https://www.tokyo-city.ru/spisok-product/Pirogi-torty.html']
#      
names_all = []
descriptions_all = []
prices_all = []
categories_all = []
url_all = []
weight_all = []
nutr_all = []
# 
for url in urllist:
    response = requests.get(url).text
    soup = BeautifulSoup(response, features="html.parser")
    items = soup.find_all('a', class_='item__name')
    itemsURL = []
    n = 0
    for n, i in enumerate(items, start=n):
        itemnotfullURL = i.get('href')
        itemURL = 'https://www.tokyo-city.ru' + itemnotfullURL
        itemsURL.extend({itemURL})
        m = 0
        namesList = []
        descriptionsList = []
        pricesList = []
        weightList = []
        nutrList = []
        itemResponse = requests.get(itemURL).text
        itemsSoup = BeautifulSoup(itemResponse, features="html.parser")
        itemsInfo = itemsSoup.find_all('div', class_='item__full-info')
        for m, u in enumerate(itemsInfo, start=m):
            if (u.find('h1', class_='item__name') == None):
                itemName = 'No data'
            else:
                itemName = u.find('h1', class_='item__name').text.strip()
            if (u.find('p', class_='item__desc') == None):
                itemDescription = 'No data'
            else:
                itemDescription = u.find('p', class_='item__desc').text.strip()
            if (u.find('span', class_='item__price-value') == None):
                itemPrice = '0'
            else:
                itemPrice = u.find('span', class_='item__price-value').text
            if (u.find('div', class_='nutr-value') == None):
                itemNutr = 'No data'
            else:
                itemNutr = u.find('div', class_='nutr-value').text.strip()
            if (u.find('div', class_='item__weight') == None):
                itemWeight = '0'
            else:
                itemWeight = u.find('div', class_='item__weight').text.strip()
            namesList.extend({itemName})
            descriptionsList.extend({itemDescription})
            pricesList.extend({itemPrice})
            weightList.extend({itemWeight})
            nutrList.extend({itemNutr})
        df = pd.DataFrame((
            {'Name': namesList,
             'Description': descriptionsList,
             'Price': pricesList,
             'Weight': weightList,
             'NutrInfo': nutrList
             }))
        names_all.extend(df['Name'])
        descriptions_all.extend(df['Description'])
        prices_all.extend(df['Price'])
        weight_all.extend(df['Weight'])
        nutr_all.extend(df['NutrInfo'])
        df['Category'] = soup.find('div', class_='title__container').text.strip()
        categories_all.extend(df['Category'])
result = pd.DataFrame((
    {'Name': names_all,
     'Description': descriptions_all,
     'Price': prices_all,
     'Category': categories_all,
     'NutrInfo': nutr_all,
     'Weight': weight_all,
     }))
print("   : " + str(datetime.datetime.now()))
      
      



- / . , . , , , - - .





- .









, , , , , , . 





:





. , . , , , , . 





  • City





“ City” 19 5 , , (, ). - 351.









“” - 13 , 301 . , “ City” , 40% , , , “”. 





  • 2





- 241 15 .





, , , . 





№1: ?

, “” .





, , , . , “”, “ ”, “”, “”, “” “” + .





:





, “2 ” - №1 . , “” (“ City” - 20, “” - 17 “2 ” - 51).





  - , “” .





№2: ?

, - “”, “” “ ”. . , , “ ”, . 





100 , :





“2 ” , “ ”. , “ + ” . “ ” “ City” “”. 





“ City” . “2 ” 2 . “” . 100 “” 30% ( , ), “ City” . 





, :





“” . “” 30% . 





“2 ” , . , “ ” , , 2 + ( ). .





“ City” .





№3: ?

, , . , . 





“ City” 205 100 , . , . “2 ” 35% , . , , , . 





: ? 

, , , , .





Trotz des höchsten Kaloriengehalts pro 100 Gramm und einer großen Menge Fast Food bietet „2 Shores“ ein ziemlich ausgewogenes Menü, während das gleiche „Tokyo City“ eine klare Tendenz zu Kohlenhydraten aufweist. 





Die BZHU "Eurasien" ist irgendwie zu einheitlich, praktisch ohne Emissionen, weshalb sie Verdacht erregt. 





Im Allgemeinen gibt es Zweifel an der Richtigkeit der Schlussfolgerungen, die ich speziell in dieser Frage gezogen habe - vielleicht müssen diese Indikatoren für die richtige Antwort auf die Frage irgendwie anders bewertet werden. 






Hier ist eine so kleine, aber merkwürdige, meiner Meinung nach entstandene Forschung aus dem zufälligen Gedanken „etwas zu analysieren“.








All Articles