標籤:domain cep \n alt color col read src pen
指令碼學習,多寫寫就會啦,來一發個人編寫的超級無敵low的子網域名稱查詢指令碼
#coding:utf-8import reimport requestsimport urllibimport urllib2import 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】子網域名稱查詢指令碼