Extracting the Ingredients from a Recipe with Regular Expressions : XML Parse : XML PYTHON examples


PYTHON examples » XML » XML Parse »

 

Extracting the Ingredients from a Recipe with Regular Expressions


 

import sys
import re

pat = r'<ingredients>((.|n)*?)</ingredients>'
filename = sys.argv[1]

data = open(filename).read()

m = re.search(pat,data)
if not m:
    print "No ingredients found"
    print sys.exit(1)

ingredients = m.group(1)

pat = r'<items.*?>(.*?)</item>'
all = re.findall(pat,ingredients)

for item in all:
    print item

   
  



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo XML
» XML Parse