End-To-End Example: SU Dining Hall Menu

Let's scrape the SU Dining Hall menu and get a list of items on the menu!


In [65]:
from bs4 import BeautifulSoup
import requests


def getHtml(date):
    url = "http://foodmenu.syr.edu/FoodPro/shortmenu.asp"
    params = { "sName" :"Syracuse University Food Services", 
              "locationNum" : 18, 
              "locationName" : "Dining Center Menu", 
              "Flag" : 1, 
              "WeeksMenus" : "This Week's Menus",
              "myaction" : "read",
              "dtdate" : date}
    response = requests.get(url, params = params)
    return response.text

def extractData(html, menu_selection):
    menu_items = []
    bld = soup.select("table[bordercolorlight=black] > tr  > td")
    for i in range(len(bld)):
        meal = bld[i]
        meal_name = meal.select("div.shortmenumeals")[0].text.lower()
        if meal_name == menu_selection:
            for item in meal.select("a[name=Recipe_Desc]"):
                menu_items.append (item.text)
    return menu_items

def printMenu(menu_items):
    print("\n\nHere's what's on the %s menu for %s" % (menu_selection, date))
    for item in menu_items:
        print("*",item)


date = input("Enter Date For Which You'd like to see the menu: MM/DD/YYYY: ")
menu_selection = input("Do you want the menu for breafast, lunch or dinner?: ")
html = getHtml(date)
menu_items = extractData(html, menu_selection) 
printMenu(menu_items)


Enter Date For Which You'd like to see the menu: MM/DD/YYYY: 3/21/2017
Do you want the menu for breafast, lunch or dinner?: dinner


Here's what's on the dinner menu for 3/21/2017
* Beef Barley Soup
* Cream of Broccoli Soup (Vegetarian)
* Macaroni Salad (Vegetarian)
* Potato Salad (Vegetarian)
* Quinoa, Garbanzo and Spinach Salad (Vegetarian)
* Tomato & Cucumber Salad (Vegan)
* Tomato and Dill Lentil Salad (Vegan)
* Tortellini Salad (Vegetarian)
* Apricot Glazed Chicken Drumsticks
* Charbroiled Steak
* Pasta Caprese (Vegetarian)
* Onions Rings (Vegetarian)
* Sweet Potato Souffle (Vegetarian)
* Mushroom and Red Bell Pepper Saute (Vegan)
* Zucchini & Yellow Squash Gratin (Vegetarian)
* Lemon Cheese Bar (Vegetarian)
* Cimbotta (Vegan)
* Great Aunt Lillian's Curried Couscous (Vegan)
* Mushroom and Red Bell Pepper Saute (Vegan)
* Root Vegetable Brown Rice Pilaf (Vegan)
* Asian Stir Fry Bar (various ingredients) (sesame)
* Beef and Snow Pea (sesame)
* Braised Vegetables with Tofu (Vegan)
* Chicken and Vegetable Dumpling (sesame)
* Jasmine Rice (Vegan)
* Vegetable Spring Roll (sesame)
* White Cake (Vegan)

In [62]:



Beef Barley Soup
Cream of Broccoli Soup (Vegetarian)
Quinoa, Garbanzo and Spinach Salad (Vegetarian)
Tomato & Cucumber Salad (Vegan)
Tomato and Dill Lentil Salad (Vegan)
Tortellini Salad (Vegetarian)
Chicken Paprikash
Pork Loin W/ Horseradish Sauce
Savory Beef Tortellini
Roasted Potatoes w/Vegetables
Mixed Vegetables (Vegan)
Squash and Pepper Melange (Vegan)
Chocolate Chip Cookies (Vegetarian)
Chocolate Mousse Pie (Vegetarian)
Basmati Rice with Peas and Carrots (Vegan)
Herbed Barley (Vegan)
Matter Paneer (Vegetarian)
Squash and Pepper Melange (Vegan)
Asian Stir Fry Bar (various ingredients) (sesame)
Beef and Snow Pea (sesame)
Braised Vegetables with Tofu (Vegan)
Chicken and Vegetable Dumpling (sesame)
Jasmine Rice (Vegan)
Vegetable Spring Roll (sesame)

In [60]:
len(bld)


Out[60]:
3

In [ ]: