Skip to content

Instantly share code, notes, and snippets.

@cjwinchester
Last active November 4, 2015 04:55
Show Gist options
  • Save cjwinchester/2d807e458a344325b634 to your computer and use it in GitHub Desktop.
Save cjwinchester/2d807e458a344325b634 to your computer and use it in GitHub Desktop.
A Python script to fetch a current list of top-level domains from IANA.
import requests
import json
def getDomainList():
url = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt"
r = requests.get(url)
s = r.text.split("\n")
date = s[0].split("Last Updated ")[1]
js = {}
clean_list = []
for dude in s[1:]:
if dude != "":
clean_list.append(dude.lower().strip())
js['updated_date'] = date
js['domains'] = clean_list
return json.dumps(js)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment