Posts Tagged ‘registered’

get registered domain in Python and Javascript

April 5, 2011

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 http://www.amazon.com or news.ycombinator.com, the task is trivial.
  • for more complicated ones, like http://www.ebay.co.uk or http://www.japantimes.co.jp, handling the second level subdomain is a little painful.
  • for exoteric ones, like nic.com.ai or http://www.nic.net.ge or 公司.cn, the problem becomes virtually impossible.
  • after seeing stupid ones, like http://www.comune.caserta.it (believe it or not, the registered domain is comune.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 availble here.

Advertisements