Skip to content

Instantly share code, notes, and snippets.

@mmattice
Last active August 9, 2017 15:42
Show Gist options
  • Save mmattice/f9cc12f9a106319a8aaba06b6d9f4169 to your computer and use it in GitHub Desktop.
Save mmattice/f9cc12f9a106319a8aaba06b6d9f4169 to your computer and use it in GitHub Desktop.
Cheap and easy advanced dns parser for namecheap
from bs4 import BeautifulSoup
html_doc=open('dns.html', 'r').read()
soup = BeautifulSoup(html_doc, 'html.parser')
table = soup.find('table', attrs={'class': 'advanced-dns'})
rows = table.findAll('tr', attrs={'class': '[object Object]'})
for row in rows:
cols = row.findAll('td')
rowtextl = [c.text.strip().replace('\n',' ') for c in cols]
removelist = (u'TTL Automatic', u'Remove Edit')
for r in removelist:
if r in rowtextl:
rowtextl.remove(r)
rowtextl[0] = rowtextl[0].replace(u'Type ', u'').replace(u' Record', u'')
rowtextl[1] = rowtextl[1].replace(u'Host ', u'')
striplist = (u'IP Address ', u'Target ', u'Nameserver ', u'Value ')
for s in striplist:
rowtextl[2] = rowtextl[2].replace(s, u'')
print rowtextl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment