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.comornews.ycombinator.com, the task is trivial. - For more complicated ones, like
www.ebay.co.ukorwww.japantimes.co.jp, handling the second level subdomain is a little painful. - For exoteric ones, like
nic.com.aiorwww.nic.net.geor公司.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.