Skip to content

Instantly share code, notes, and snippets.

@techstiff
Created March 11, 2014 14:48
Show Gist options
  • Save techstiff/9487304 to your computer and use it in GitHub Desktop.
Save techstiff/9487304 to your computer and use it in GitHub Desktop.
Check Domain Availability with Python
import urllib2,cookielib
import re
def checkDomain(domain):
site='http://www.checkdomain.com/cgi-bin/checkdomain.pl?domain=' + domain
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
req = urllib2.Request(site, headers=hdr)
response = urllib2.urlopen(req)
data = response.read()
pat = re.compile("has already been registered by the organization below")
if pat.search(data) is None:
print "Domain %s : Available" %(domain)
else:
print "Domain %s : Not Available" %(domain)
fo = open("domains.txt",'r')
domains = fo.readlines()
fo.close()
for domain in domains:
domain = domain.strip()
checkDomain(domain)
@bidhyapokharel
Copy link

Hey, I've a list of domains in txt file('links_txt') and I'm trying to check the domain availability via godaddy api. and want to keep the available domain name in another txt file....I ran the code like below:
`import requests
import time
import json

api_key = "3mM44UaguNL6GH_Kc3bKzig25G1mZtnA87nwS"
secret_key = "37ZnMbQkQrYJ5pF57ZhrEi"

headers = {"Authorization" : "sso-key {}:{}".format(api_key, secret_key)}

url = "https://api.godaddy.com/v1/domains/available"
all_domains=[]

with open("links.txt") as f:
for domains in f:
availability_res = requests.post(url, json=domains, headers=headers)
for domain in json.loads(availability_res.text)["domains"]:
if domain["available"]:
with open("available_domains.txt", 'w', newline="", encoding="UTF-8") as f:
f.write(domain)
print("Not Available")

but it shows the error like :for domain in json.loads(availability_res.text)["domains"]:
KeyError: 'domains'.

If you have any idea...what am I doing wrong....
Can you help me with it??
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment