Created
March 27, 2015 10:01
-
-
Save guewen/698a100f62abcad13940 to your computer and use it in GitHub Desktop.
Puur menus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
from urllib2 import urlopen | |
import bs4 as BeautifulSoup | |
html = urlopen('http://menus.epfl.ch/cgi-bin/getMenus?resto_id=42&pagejahia=1') | |
soup = BeautifulSoup.BeautifulSoup(html) | |
menus = soup.find(id='menulist') | |
for menu in menus.findAll('li'): | |
title = menu.find('div', attrs={'class': 'resto'}).text.strip() | |
texts = menu.find('div', attrs={'class': 'desc'}) | |
descr = texts.strong.text.strip() | |
accompaniments = [line.strip() for line in texts.contents[2:] | |
if isinstance(line, basestring) and | |
line.strip()] | |
if accompaniments: | |
descr = "%s %s" % (descr, "(%s)" % ', '.join(accompaniments)) | |
price = "[%s]" % menu.find('span').next.strip() | |
print('***', title, ':', descr, price) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment