Parsing XML from NameCheap that says my domain is not available


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # Userful: http://blog.doughellmann.com/2010/03/pymotw-parsing-xml-documents-with.html
  2.  
  3. from xml.etree import ElementTree
  4.  
  5. foo = """<?xml version="1.0" encoding="utf-8"?>
  6. <ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response">
  7. <Errors />
  8. <Warnings />
  9. <RequestedCommand>namecheap.domains.check</RequestedCommand>
  10. <CommandResponse>
  11. <DomainCheckResult Domain="example.com" Available="false" />
  12. </CommandResponse>
  13. <Server>P2136033</Server>
  14. <GMTTimeDifference>--7:00</GMTTimeDifference>
  15. <ExecutionTime>0.688</ExecutionTime>
  16. </ApiResponse>"""
  17.  
  18. tree = ElementTree.fromstring(foo)
  19. print tree
  20.  
  21. for node in tree.getiterator():
  22. print node.tag, ": ", node.attrib
  23.  
  24. print "\n--------------------\n"
  25.  
  26. for node in tree.getiterator():
  27. if "Available" in node.attrib.keys():
  28. print node.attrib["Available"]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.