Advice for a python newbie on parsing whois records?

Miki miki.tebeka at gmail.com
Tue Jun 10 21:21:33 CEST 2008


Hello,

> Hi. I'm stretching my boundaries in programming with a little python
> shell-script which is going to loop through a list of domain names,
> grab the whois record, parse it, and put the results into a csv.
>
> I've got the results coming back fine, but since I have *no*
> experience with python I'm wondering what would be the preferred
> "pythonic" way of parsing the whois string into a csv record.
>
> Tips/thoughts/examples more than welcome!

from os import popen
import re

find_record = re.compile("\s+([^:]+): (.*)\s*").match
for line in popen("whois google.com"):
    match = find_record(line)
    if not match:
        continue
    print "%s --> %s" % (match.groups()[0], match.groups()[1])

HTH,
--
Miki <miki.tebeka at gmail.com>
http://pythonwise.blogspot.com



More information about the Python-list mailing list