Skip to content

Instantly share code, notes, and snippets.

@vivien
Created November 10, 2011 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivien/1356660 to your computer and use it in GitHub Desktop.
Save vivien/1356660 to your computer and use it in GitHub Desktop.
List of (ascii only) Internet top-level domains (TLD)
#!/usr/bin/env ruby
# An approximative Wikipedia/Mechanize version of:
# curl -s http://data.iana.org/TLD/tlds-alpha-by-domain.txt | grep -v XN | sed -e 1d -e 's/\(.*\)/\L\1/'
# Vivien Didelot <vivien@didelot.org>
require 'mechanize'
wikipedia_page = "http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains"
agent = Mechanize.new
agent.user_agent = "Mac Safari"
page = agent.get(wikipedia_page)
tlds = page.search("td/a").collect { |a| a.text if a.text[0] == "." && a.text.ascii_only? }.compact.sort.uniq
puts tlds.join("\n")
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment