python 获取域名的IP注册时间过期时间
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 获取域名的IP注册时间过期时间相关的知识,希望对你有一定的参考价值。
import requests
import json
import asyncio
import aiohttp
from bs4 import BeautifulSoup
import datetime
result1={"baidu":{"domain_name":"www.baidu.com"}}
result2=[]
async def get_title(k,i):
if ‘http://‘ in i :
i = i[7:]
url = ‘http://seo.chinaz.com/?q={}‘.format(i)
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
text = await resp.text()
soup = BeautifulSoup(text, ‘html.parser‘)
try:
ret_time = soup.find(‘div‘, class_=‘w97-0 brn col-hint02 pl0‘).text.split(‘于‘)[1].split(‘,‘)
ctime = ret_time[0][:-1].replace(‘年‘, ‘-‘).replace(‘月‘, ‘-‘)+ ‘ 00:00‘
etime = ret_time[1].split(‘为‘)[1][:-2].replace(‘年‘, ‘-‘).replace(‘月‘, ‘-‘)+ ‘ 00:00‘
try:
lis = soup.find(‘div‘, class_=‘brn ipmW‘).text
lis_ip = (lis[3:].split(‘[‘))[0]
except Exception as e:
print("没有IP", e)
lis_ip = ‘0.0.0.0‘
a = {k:{‘name‘:i,‘ip‘:lis_ip,‘ctime‘:ctime,‘etime‘:etime,‘comment‘:k}}
result2.append(a)
except Exception as e:
print("域名没查到",e)
b = {k:{‘name‘:i,‘ipd‘:‘0.0.0.0‘,‘ctime‘: datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M‘) ,‘etime‘:datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M‘),‘comment‘:k }}
result2.append(b)
loop = asyncio.get_event_loop()
fun_list = (get_title(k=k,i=n) for index, i in enumerate(result1) for k, v in i.items() for m, n in v.items() )
loop.run_until_complete(asyncio.gather(*fun_list))
print(result2)
以上是关于python 获取域名的IP注册时间过期时间的主要内容,如果未能解决你的问题,请参考以下文章