域名过期提前通知脚本

论坛 期权论坛 脚本     
匿名技术用户   2020-12-21 19:31   11   0


#!/root/.virtualenvs/script/bin/python

#coding=utf-8

import re

import time, mechanize

import urllib2

import random

URL = 'http://whois.chinaz.com/'

def str_cut(str,startsep,endsep):

str1=str.split(startsep)[1]

str2=str1.split(endsep)[0]

return str2

br = mechanize.Browser()

br.set_handle_equiv(True)

br.set_handle_gzip(False)

br.set_handle_redirect(True)

br.set_handle_referer(True)

br.set_handle_robots(True)

br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

#br.set_debug_http(True)

#br.set_debug_redirects(True)

#br.set_debug_responses(True)

br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.

1')]

domain_list = [你的域名列表]

r = br.open(URL)

for index, item in enumerate(domain_list):

try:

br.select_form(nr=0)

br.form['DomainName'] = item

br.submit()

contents = br.response().read()

if contents.find('<div id="whoisinfo" class="div_whois">')==-1:

print item + " " + "not found"

else:

contents=str_cut(contents,'<div id="whoisinfo" class="div_whois">','</div>')

contents=contents.replace('<br/>',',')[:-1]

a = re.split(',',contents)

for i in a:

m = re.match(r"过期时间", i)

if m:

print '域名 : %s, 过期时间 : %s' % (item, re.sub(r"年|月", '-', i[15:-3]).strip()[:10])

br.back()

except Exception,e:

print Exception,":",e

time.sleep(1.27*random.randint(4, 12))


本文出自 “xinsz08の平行时空” 博客,请务必保留此出处http://xinsz08.blog.51cto.com/10565212/1915945

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP