脚本学习,多写写就会啦,来一发个人编写的超级无敌low的子域名查询脚本

#coding:utf-8

import re
import requests
import urllib
import urllib2
import bs4  
from bs4 import BeautifulSoup  

key=raw_input("please input top domain: ")

print "查询马上开始..."
title=[]
domainlist=[]
for n in xrange(1,66):
    if n!=1:
        n*=10        
    url="https://cn.bing.com/search?q=domain:"+key+"&first=%s" % n    
    try:
        req=urllib2.Request(url)
        resp=urllib2.urlopen(req).read()
        #BeautifulSoup匹配标题
        bsObj=BeautifulSoup(resp,"lxml")
        getList=bsObj.find_all("h2",{"class":""})
        for t in getList:
            title.append(t.get_text())
        #正则匹配子域名
        regex=re.compile('<cite>(.*?)</cite>').findall(resp)
        for i in regex:
            domainlist.append(i.strip('https://').strip('http://').split('/')[0])
        #同步输出查询到的标题和子域名
        for (i,j) in zip(title,domainlist):
            print "%-50s%-30s" % (i,j)
    except Exception,e:
        print e    
print "查询已全部完成..."
#去掉重复的子域名
domainlists=list(set(domainlist))
#保存子域名
for line in domainlists:
    with open('subdomain.txt','a') as fw:
        fw.write(line+'\n')

运行截图:

【Python】子域名查询脚本

运行结果截图:

【Python】子域名查询脚本

 

相关文章:

  • 2022-02-04
  • 2021-10-16
  • 2022-12-23
  • 2021-11-04
  • 2021-11-07
  • 2022-02-26
  • 2022-01-18
猜你喜欢
  • 2022-01-18
  • 2022-01-05
  • 2022-12-23
  • 2021-10-14
  • 2021-07-21
  • 2022-12-23
  • 2021-09-25
相关资源
相似解决方案