def convert_xml_to_csv():
 try:
  phishtank_db_fd = file(XML_DB_FILE, 'r')
 except Exception as e:
  msg = 'Failed to open XML phishtank database: "%s", exception: "%s".'
  sys.exit((msg % (XML_DB_FILE, e)))
 try:
  output_csv_file = file(CSV_DB_FILE, 'w')
 except Exception as e:
  msg = 'Failed to open CSV phishtank database: "%s", exception: "%s".'
  sys.exit((msg % (CSV_DB_FILE, e)))
 pt_handler = PhishTankHandler(output_csv_file)
 parser = etree.HTMLParser(recover=True, target=pt_handler)
 print 'Starting the phishtank XML conversion.'
 try:
  etree.parse(phishtank_db_fd, parser)
 except Exception as e:
  msg = 'XML parsing error in phishtank DB, exception: "%s".'
  sys.exit((msg % e))
 print 'Finished XML conversion.'

def convert_xml_to_csv ( ) : try : phishtank_db_fd = file ( XML_DB_FILE , 'r' ) except Exception as e : msg = 'Failed to open XML phishtank database: "%s", exception: "%s".' sys . exit ( ( msg % ( XML_DB_FILE , e ) ) ) try : output_csv_file = file ( CSV_DB_FILE , 'w' ) except Exception as e : msg = 'Failed to open CSV phishtank database: "%s", exception: "%s".' sys . exit ( ( msg % ( CSV_DB_FILE , e ) ) ) pt_handler = PhishTankHandler ( output_csv_file ) parser = etree . HTMLParser ( recover = True , target = pt_handler ) print 'Starting the phishtank XML conversion.' try : etree . parse ( phishtank_db_fd , parser ) except Exception as e : msg = 'XML parsing error in phishtank DB, exception: "%s".' sys . exit ( ( msg % e ) ) print 'Finished XML conversion.'
had to do this because xml parsing with lxml is slow and memory intensive .