Created
March 10, 2014 07:17
-
-
Save jugyo/9460736 to your computer and use it in GitHub Desktop.
Script to get TLDs from iana.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'nokogiri' | |
doc = Nokogiri::HTML(open('http://www.iana.org/domains/root/db')) | |
tlds = [] | |
doc.css('table#tld-table tr').each do |tr| | |
info = tr.css('td') | |
next if info.empty? | |
tlds << { | |
domain: info[0].text.gsub('.', ''), | |
type: info[1].text | |
} | |
end | |
def print_tld(tlds, type) | |
puts tlds.select {|i| i[:type] =~ type}.map {|i| i[:domain]}.sort.join("|") | |
end | |
puts "# country-code" | |
print_tld(tlds, /country\-code/) | |
puts "# generic" | |
print_tld(tlds, /generic|sponsored|infrastructure|generic-restricted/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment