Get registered domain in Python and Javascript
reg-dom-libs are a set of libraries for C
, PHP
and Perl
to convert an arbitrary domain name to the registered domain name.
- For simple domains, like
www.amazon.com
ornews.ycombinator.com
, the task is trivial. - For more complicated ones, like
www.ebay.co.uk
orwww.japantimes.co.jp
, handling the second level subdomain is a little painful. - For exoteric ones, like
nic.com.ai
orwww.nic.net.ge
or公司.cn
, the problem becomes virtually impossible. - After seeing stupid ones, like
www.comune.caserta.it
(believe it or not, the registered domain iscomune.caserta.it
!), I gave up finding an elegant algorithm for the problem. - A full list of valid registered domain is necessary. Luckily, it is available (and nightly updated) here.
Inspired by reg-dom-libs, I've ported the algorithm to Python and Javascript. See the tests at the end of each file for an example of the usage. A demo is available here.