• Python2 查询域名(网址)过期时间


    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    # __author__ = 'kiki'
    import urllib2
    import time
    from bs4 import BeautifulSoup
    import sys

    reload(sys)
    sys.setdefaultencoding('utf8')


    def getexpiredate(domain):
    url = "http://tool.chinaz.com/DomainDel/?wd=" + domain # domaintxt文件,存储要查询的url
    header = {'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'}
    request = urllib2.Request(url, None, header)
    response = urllib2.urlopen(request, None, timeout=30).read()
    soup = BeautifulSoup(response, "html.parser", from_encoding='utf-8')
    content = soup.find_all('div', attrs={'class': 'fr zTContrig'})
    title = '<tr align="center"><td>%s</td> ' % domain
    f = open('DomainExpireDate.html', 'a+')
    f.write(title)
    time.sleep(2)
    for div in content:
    for i in div.strings:
    table_text = "<td>%s</td> " % i
    f.write(table_text)
    f.write('</tr> ')


    if __name__ == "__main__":
    with open('DomainExpireDate.html', 'w') as DomainExpireDate:
    head = '<html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>DomainExpireDate</title> <style type="text/css">thead {color:green; height:50px;} tbody{color:blue; height:50px}</style></head> <body> <table width="1000" border="1" align="center"> <caption align="top">域名过期时间表</caption> '
    table_head = '<thead><tr align="center" bgcolor="#ccc"><th>Domain</th><th>域名年龄</th><th>域名创建时间</th><th>域名过期时间</th><th>域名删除时间</th><th>删除倒计时</tr></tr></thead> <tbody> '
    DomainExpireDate.write(head)
    DomainExpireDate.write(table_head)
    with open('domains.txt', 'r') as domains:
    for domain in domains.read().splitlines():
    getexpiredate(domain)
    with open('DomainExpireDate.html', 'a+') as DomainExpireDate:
    DomainExpireDate.write('</tbody> </body> </html>')

    一个最直接的方法就是使用whois模块

    import whois
    
    a = whois.whois('baidu.com')
    print(a["expiration_date"][0])
  • 相关阅读:
    HolidayFileDisPersonViewList.js中的一些基础
    保存会话数据的两种技术,Cookie,Session
    web服务器调用Servlet的过程
    XML基础
    HttpServletRequest,HttpServletResponse
    金蝶handler中 collection 代码片段理解
    Rancher 容器云平台搭建
    Docker的安装及镜像加速配置
    MYSQL 合并行
    Spring Ioc 容器核心概览
  • 原文地址:https://www.cnblogs.com/qiqi-yhq/p/12028326.html
Copyright © 2020-2023  润新知