我正在创建一个 python 脚本,它遍历包含域名的列表,在大多数情况下它运行良好(使用从 下载的包https://bitbucket.org/richardpenman/pywhois
),但有时我收到错误消息:Socket Error: [Errno 10054] An existing connection was forcibly closed by the remote host
我可以忽略这个错误吗?
我的python代码是:
import whois
import csv
from datetime import datetime
import sys
import time
def getDomainExpirationDate(domainName):
f = open('domain.csv', 'w')
w = whois.whois(domainName[1])
#print(w)
expirationDate = w.expiration_date
if expirationDate != None:
if type(expirationDate) is list:
try:
delta = expirationDate[0] - now
except:
print sys.exc_info()[0]
else:
try:
delta = expirationDate - now
except:
print sys.exc_info()[0]
data = domainName[0] +','+ domainName[1] + ',' + str(delta.days)
if w.status == None:
message = data + ",No status info found\n"
f.write(message)
else:
print data
f.close()
now = datetime.now()
with open('top-1m.csv', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in reader:
getDomainExpirationDate(row)
域列表(但我知道这无关紧要):
1,google.com
2,facebook.com
...
感谢您的回答!