Quantcast
Viewing all articles
Browse latest Browse all 46

python-whois showing different results

I made a script that opens the csv file which contains multiple domain names and then uses python-whois module to find the emails for each domain.

import whoisimport csvwith open('emails.csv', 'r', newline='') as f:    reader = csv.reader(f)    distro = [row for row in reader]with open('emails_done.csv', 'w', newline='') as f:    wr = csv.writer(f)    for s in distro:        try:            if whois.whois(s[0]).emails is not None:                if len(whois.whois(s[0]).emails[0]) == 1:                    wr.writerow([s[0]] + [whois.whois(s[0]).emails])                else:                    wr.writerow([s[0]] + whois.whois(s[0]).emails)            elif whois.whois(s[0]).registrant_email is not None:                print(whois.whois(s[0]).registrant_email[1])                wr.writerow([s[0]] + [whois.whois(s[0]).registrant_email])            else:                wr.writerow([s[0]] + ['nothing found'])        except Exception as e:            print(e)            wr.writerow([s[0]] + ['invaliddomain'])

The problem is that this module gives me different data for the same domain every time I run a code. For example, the first time I used ".emails" method on the domain it returned a list of 2 emails, but when I re-run the same code for the second time it returned me a string with 1 email instead of a list. ".emails" method I used in the code returns a list of all emails it found from the whois data if there's more than 1 email available, but it returns a string instead of list if there's only 1 email available, so I need to convert this string into the list so I can put it in csv.writerow method. Is there a mistake from my side or it's just the way this module works and there's nothing I can do about it?


Viewing all articles
Browse latest Browse all 46

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>