# HG changeset patch # User Richard Baron Penman # Date 1357623783 -39600 # Node ID 5083c26d8f93d719d0011089690687c862997ddb # Parent 169462701583d29131739877063414d79af973ed added support for .pl domain diff -r 169462701583 -r 5083c26d8f93 pywhois/__init__.py --- a/pywhois/__init__.py Tue Jan 08 16:27:34 2013 +1100 +++ b/pywhois/__init__.py Tue Jan 08 16:43:03 2013 +1100 @@ -10,6 +10,7 @@ # clean domain to expose netloc domain = extract_domain(url) try: + raise OSError() # try native whois command first r = subprocess.Popen(['whois', domain], stdout=subprocess.PIPE) text = r.stdout.read() @@ -26,12 +27,15 @@ >>> extract_domain('http://www.google.com.au/tos.html') 'google.com.au' + >>> extract_domain('http://blog.webscraping.com') + 'webscraping.com' >>> extract_domain('69.59.196.211') 'stackoverflow.com' """ if re.match(r'\d+.\d+.\d+.\d+', url): # this is an IP address return socket.gethostbyaddr(url)[0] + suffixes = 'ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn', 'mo', 'mobi', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc', 'ne', 'net', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt', 'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'xn', 'ye', 'yt', 'za', 'zm', 'zw' url = re.sub('^.*://', '', url).split('/')[0].lower() domain = [] diff -r 169462701583 -r 5083c26d8f93 pywhois/parser.py --- a/pywhois/parser.py Tue Jan 08 16:27:34 2013 +1100 +++ b/pywhois/parser.py Tue Jan 08 16:43:03 2013 +1100 @@ -116,6 +116,8 @@ return WhoisFi(domain, text) elif domain.endswith('.jp'): return WhoisJp(domain, text) + elif domain.endswith('.pl'): + return WhoisPl(domain, text) else: return WhoisEntry(domain, text) @@ -271,7 +273,27 @@ raise PywhoisError(text) else: WhoisEntry.__init__(self, domain, text, self.regex) - + + +class WhoisPl(WhoisEntry): + """Whois parser for .uk domains + """ + regex = { + 'domain_name': 'DOMAIN NAME:\s*(.+)\n', + 'registrar': 'REGISTRAR:\n\s*(.+)', + 'registrar_url': 'URL:\s*(.+)', # not available + 'status': 'Registration status:\n\s*(.+)', # not available + 'registrant_name': 'Registrant:\n\s*(.+)', # not available + 'creation_date': 'created:\s*(.+)\n', + 'expiration_date': 'renewal date:\s*(.+)', + 'updated_date': 'last modified:\s*(.+)\n', + } + def __init__(self, domain, text): + if 'Not found:' in text: + raise PywhoisError(text) + else: + WhoisEntry.__init__(self, domain, text, self.regex) + class WhoisMe(WhoisEntry): """Whois parser for .me domains