Skip to content

Instantly share code, notes, and snippets.

@QuanSai
Created February 14, 2016 01:41
Show Gist options
  • Save QuanSai/a051251204f1ed2ddcf9 to your computer and use it in GitHub Desktop.
Save QuanSai/a051251204f1ed2ddcf9 to your computer and use it in GitHub Desktop.
Extract domain expiration data from domain.com
import sys
import urllib2
from bs4 import BeautifulSoup
if __name__=="__main__":
REGISTRAR = "http://whois.com/whois/"
# ask the user for the domain name if a domain was not passed in
try:
domain = sys.argv[1]
except IndexError:
domain = raw_input("Domain?: ")
domain_to_check = REGISTRAR + domain
# requests to the registrar
registrar_response = urllib2.Request(domain_to_check)
status_page_text = urllib2.urlopen(registrar_response) # raw html text
# store the page as a BeautifulSoup object
parsed_status_page = BeautifulSoup(status_page_text, "html.parser")
expiration_date = parsed_status_page.find('div',
class_='whois_result',
id='registryData')
# filter the <br>'s found in the status section of the page
expiration = filter(lambda x: x.text.startswith('Expiration Date'), expiration_date.findAll('br'))
# clean the expiration status (remove extra whitespace) and the prefix "Expiration Date"
expiration_date = expiration[0].text.split(':')[1].strip()
# tell that bitch wtf it is... ya heard meh?
print "The expiration date for '{}' is {}".format(domain, expiration_date)
beautifulsoup4==4.4.1
urllib3==1.14
wsgiref==0.1.2
@QuanSai
Copy link
Author

QuanSai commented Feb 14, 2016

To get this to work, download both files and inside of the directory (unzip them or whatever):

pip install -r requirements.txt

Then, type python domainexp.py cool.com

If you don't specify a domain name, you'll be prompted to specify one.

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