File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change
1
+ dinner_recipe = '''<html><body><table>
2
+ <tr><th>amt</th><th>unit</th><th>item</th></tr>
3
+ <tr><td>24</td><td>slices</td><td>baguette</td></tr>
4
+ <tr><td>2+</td><td>tbsp</td><td>olive oil</td></tr>
5
+ <tr><td>1</td><td>cup</td><td>tomatoes</td></tr>
6
+ <tr><td>1</td><td>jar</td><td>pesto</td></tr>
7
+ </table></body></html>'''
8
+
9
+ # From http://effbot.org/zone/element-index.htm
10
+ import xml.etree.ElementTree as etree
11
+ tree = etree.fromstring(dinner_recipe)
12
+
13
+ # For invalid HTML use http://effbot.org/zone/element-soup.htm
14
+ # import ElementSoup, StringIO
15
+ # tree = ElementSoup.parse(StringIO.StringIO(dinner_recipe))
16
+
17
+ pantry = set(['olive oil', 'pesto'])
18
+ for ingredient in tree.getiterator('tr'):
19
+ amt, unit, item = ingredient
20
+ if item.tag == "td" and item.text not in pantry:
21
+ print ("%s: %s %s" % (item.text, amt.text, unit.text))
You can’t perform that action at this time.
0 commit comments