码迷,mamicode.com
首页 > 编程语言 > 详细

【Python】子域名查询脚本

时间:2018-04-14 13:59:36      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:domain   cep   \n   alt   color   col   read   src   pen   

脚本学习,多写写就会啦,来一发个人编写的超级无敌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】子域名查询脚本

标签:domain   cep   \n   alt   color   col   read   src   pen   

原文地址:https://www.cnblogs.com/peterpan0707007/p/8831183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!