2014-10-10 95 views
-5

列表我使用的模塊pythonwhois得到許多條目的特定域列表:遍歷在Python

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

上述返回條目喜歡的列表如下:

[u「域名:google.com \ n註冊域名ID:\ n註冊商WHOIS服務器:whois.markmonitor.com \ n註冊商網址:http://www.markmonitor.com \ n更新日期:2014-05-19T04:00:17-0700 \ n創建日期:1997- 09-15T00:00:00-0700 \ n註冊處註冊到期日:2020-09-13T21:00:00-0700 \ n

我的問題是:我如何迭代列表並將結果打印在一個優雅的人類可讀列表中?

回答

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: [email protected] 
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),然後瀏覽返回的字典格式並顯示感興趣的字段。

0

使用pprint爲你做。

from pprint import pprint 
pprint(whois)