-5

I'm using the module pythonwhois to get a list of many entries on specific domains:

def whois(self):
    host = str(self.EntryText.get().lstrip("http://www."))
    whois = pythonwhois.net.get_whois_raw(host)
    print whois
whois

the above returns a list of entries like follows:

[u"Domain Name: google.com\nRegistry Domain ID: \nRegistrar WHOIS Server: whois.markmonitor.com\nRegistrar URL: http://www.markmonitor.com\nUpdated Date: 2014-05-19T04:00:17-0700\nCreation Date: 1997-09-15T00:00:00-0700\nRegistrar Registration Expiration Date: 2020-09-13T21:00:00-0700\n

My question is: how do I iterate over the list and print the results in an elegant human readable list?

The One Electronic
  • 129
  • 1
  • 1
  • 9

2 Answers2

0

Use pprint to do it for you.

from pprint import pprint
pprint(whois)
Holloway
  • 6,412
  • 1
  • 26
  • 33
0

A simple way is to simply print each string in the returned whois:

host = 'stackoverflow.com'
whois = pythonwhois.net.get_whois_raw(host)
for item in whois:
    print item

This would output something like this:

Domain Name: STACKOVERFLOW.COM 
Registrar WHOIS Server: whois.name.com 
Registrar URL: http://www.name.com 
Updated Date: 2014-05-09T17:51:17-06:00 
Creation Date: 2003-12-26T19:18:07-07:00 
Registrar Registration Expiration Date: 2015-12-26T19:18:07-07:00 
Registrar: Name.com, Inc. 
Registrar IANA ID: 625 
Registrar Abuse Contact Email: abuse@name.com 
Registrar Abuse Contact Phone: +1.17202492374 
Reseller:  
Domain Status: clientTransferProhibited 
Registrant Name: Sysadmin Team 
Registrant Organization: Stack Exchange, Inc. 
Registrant Street: 1 Exchange Plaza , Floor 26 
Registrant City: New York 
Registrant State/Province: NY 
Registrant Postal Code: 10006 
Registrant Country: US 
etc.

Anything more elegant than this will require that you use pythonwhois.get_whois(host) and then navigate through the returned dictionary formatting and displaying the fields of interest.

mhawke
  • 84,695
  • 9
  • 117
  • 138