From anonymous, 9 Years ago, written in Python.
Embed
  1. import xml.dom.minidom as minidom
  2. import urllib
  3.  
  4. def getTitles(xml):
  5.     """
  6.    Print out all titles found in xml
  7.    """
  8.     doc = minidom.parse(xml)
  9.     node = doc.documentElement
  10.     books = doc.getElementsByTagName("CompleteSuggestion")
  11.  
  12.     titles = []
  13.     for book in books:
  14.         titleObj = book.getElementsByTagName("suggestion data")[0]
  15.         titles.append(titleObj)
  16.  
  17.     for title in titles:
  18.         nodes = title.childNodes
  19.         for node in nodes:
  20.             if node.nodeType == node.TEXT_NODE:
  21.                 print node.data
  22.  
  23. if __name__ == "__main__":
  24.     f = urllib.urlopen("http://google.com/complete/search?output=toolbar&q=google")
  25.     document = f
  26.     getTitles(document)