迭代python中的列表

时间:2014-10-10 09:53:27

标签: python python-2.7 whois

我使用模块pythonwhois获取特定域上的许多条目列表:

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

以上返回的条目列表如下:

  

[u"域名:google.com \ nRegistry域名ID:\ nRegistrar WHOIS服务器:whois.markmonitor.com \ nRegistrar网址:http://www.markmonitor.com \ n更新日期:2014-05-19T04:00: 17-0700 \ n创建日期:1997-09-15T00:00:00-0700 \ nRegistrar Registration Expiration Date:2020-09-13T21:00:00-0700 \ n

我的问题是:如何迭代列表并将结果打印在优雅的人类可读列表中?

2 个答案:

答案 0 :(得分:0)

使用pprint为您完成。

from pprint import pprint
pprint(whois)

答案 1 :(得分:0)

一种简单的方法是在返回的whois

中简单地打印每个字符串
host = 'stackoverflow.com'
whois = pythonwhois.net.get_whois_raw(host)
for item in whois:
    print item

这将输出如下内容:

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.

比这更优雅的东西要求您使用pythonwhois.get_whois(host),然后浏览返回的字典格式并显示感兴趣的字段。

相关问题