python 擷取網域名稱的IP、註冊時間、到期時間

來源:互聯網
上載者:User

標籤:網域名稱   domain name   python   註冊時間   

import requestsimport jsonimport asyncioimport aiohttpfrom bs4 import BeautifulSoupimport datetimeresult1={"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、註冊時間、到期時間

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.