Skip to content

Instantly share code, notes, and snippets.

@polera
Created February 4, 2010 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polera/294341 to your computer and use it in GitHub Desktop.
Save polera/294341 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from BeautifulSoup import BeautifulStoneSoup
xml_data = """<xml>
<response>
<results>
<result>
<fname>Brian</fname>
<lname>Jones</lname>
<gender>M</gender>
<office_phone_ext>777</office_phone_ext>
<mobile_phone>201-555-1212</mobile_phone>
</result>
<result>
<fname>Molly</fname>
<lname>Jones</lname>
<home_phone>201-555-1234</home_phone>
</result>
</results>
</response>
</xml>"""
xml = BeautifulStoneSoup(xml_data)
for result in xml.findAll("result"):
home_phone = getattr(result.home_phone,'string',None)
print home_phone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment