这听起来像pywhois一遍。
基础入门级是一个很好的例子,看起来像这样:
class WhoisEntry(object):
"""Base class for parsing a Whois entries.
"""
# regular expressions to extract domain data from whois profile
# child classes will override this
_regex = {
'domain_name': 'Domain Name:\s?(.+)',
'registrar': 'Registrar:\s?(.+)',
'whois_server': 'Whois Server:\s?(.+)',
'referral_url': 'Referral URL:\s?(.+)', # http url of whois_server
'updated_date': 'Updated Date:\s?(.+)',
'creation_date': 'Creation Date:\s?(.+)',
'expiration_date': 'Expiration Date:\s?(.+)',
'name_servers': 'Name Server:\s?(.+)', # list of name servers
'status': 'Status:\s?(.+)', # list of statuses
'emails': '[\w.-][email protected][\w.-]+\.[\w]{2,4}', # list of email addresses
}
def __init__(self, domain, text, regex=None):
self.domain = domain
self.text = text
if regex is not None:
self._regex = regex
def __getattr__(self, attr):
"""The first time an attribute is called it will be calculated here.
The attribute is then set to be accessed directly by subsequent calls.
"""
whois_regex = self._regex.get(attr)
if whois_regex:
setattr(self, attr, re.findall(whois_regex, self.text))
return getattr(self, attr)
else:
raise KeyError('Unknown attribute: %s' % attr)
def __str__(self):
"""Print all whois properties of domain
"""
return '\n'.join('%s: %s' % (attr, str(getattr(self, attr))) for attr in self.attrs())
def attrs(self):
"""Return list of attributes that can be extracted for this domain
"""
return sorted(self._regex.keys())
@staticmethod
def load(domain, text):
"""Given whois output in ``text``, return an instance of ``WhoisEntry`` that represents its parsed contents.
"""
if text.strip() == 'No whois server is known for this kind of object.':
raise PywhoisError(text)
if '.com' in domain:
return WhoisCom(domain, text)
elif '.net' in domain:
return WhoisNet(domain, text)
elif '.org' in domain:
return WhoisOrg(domain, text)
elif '.ru' in domain:
return WhoisRu(domain, text)
elif '.name' in domain:
return WhoisName(domain, text)
elif '.us' in domain:
return WhoisUs(domain, text)
elif '.me' in domain:
return WhoisMe(domain, text)
elif '.uk' in domain:
return WhoisUk(domain, text)
else:
return WhoisEntry(domain, text)
编辑:因为我不能上斯文的回答发表评论,你可以很容易地处理存储在像这样一本字典:
scanner = new Scanner()
scanner.self.emails = '[email protected]'
scanner.self.expiration_date = 'Tomorrow'
scan_data_dict = scanner.__dict__
@ Back2Basics它不是。这是为了工作。我们正在转向新的主机,所以我们需要所有的数据。我会发布我到目前为止的代码 – PintSizeSlash3r