首页 > 其他分享 >url批量获取title文件

url批量获取title文件

时间:2023-04-24 12:56:35浏览次数:37  
标签:30x 批量 title url req headers strip

import chardet
import requests,re
from threading import Thread,activeCount
from sys import argv
from queue import Queue


requests.packages.urllib3.disable_warnings()
new_targets = []

def get_banner(url):
        if 'http://' or 'https://' not in url.strip(): #判断有无协议
            target = 'http://' + url.strip()
        try:
            req = requests.get(target,verify=False,allow_redirects=False,timeout=(5,20))
            if 'charset' not in req.headers.get('Content-Type', " "):
                req.encoding = chardet.detect(req.content).get('encoding')  # 解决网页编码问题
            code = req.status_code
            if '30' in str(code):
                if req.headers['Location'] == 'https://' + target.strip('http://') + '/':
                    req_30x = requests.get('https://{}'.format(target.strip('http://')),verify=False,timeout=(5,20))
                    code_30x = str(req_30x.status_code).strip()
                    if 'charset' not in req_30x.headers.get('Content-Type', " "):
                        req_30x.encoding = chardet.detect(req_30x.content).get('encoding')  # 解决网页编码问题
                    try:
                        title_30x = re.findall(r'<title>(.*?)</title>',req_30x.text,re.S)[0].strip()
                    except:
                        title_30x = 'None'
                    if 'Server' in req_30x.headers:
                        server_30x = req_30x.headers['Server'].strip()
                    else:
                        server_30x = ''
                    if 'Content-Type' in req_30x.headers:
                        type_30x = req_30x.headers['Content-Type'].strip()
                    else:
                        type_30x = ''
                    if 'X-Powered-By' in req_30x.headers:
                        x_powered_by_30x = req_30x.headers['X-Powered-By'].strip()
                    else:
                      x_powered_by_30x = ''
                    print('[+] {} {} {} {} {} {} '.format(code_30x,target,title_30x,server_30x,type_30x,x_powered_by_30x))
                    write_info(target,code_30x,title_30x, server_30x, type_30x,x_powered_by_30x)
                else:
                    title = '302_redirection'
                    location = req.headers['Location']
                    print('[+] {} {} {} Location:{}'.format(code,target,title,location))
                    write_info(target,code,title,location=location)
            else:
                try:
                    title = re.findall(r'<title>(.*?)</title>',req.text,re.S)[0].strip()
                except:
                    title = 'None'
                if 'Server' in req.headers:
                    server = req.headers['Server'].strip()
                else:
                    server = ''
                if 'Content-Type' in req.headers:
                    type = req.headers['Content-Type'].strip()
                else:
                    type = ''
                if 'X-Powered-By' in req.headers:
                    x_powered_by = req.headers['X-Powered-By'].strip()
                else:
                    x_powered_by = ''
                write_info(target,code,title,server,type,x_powered_by)
                print('[+] {} {} {} {} {}'.format(code,target,title,server,x_powered_by))
        except Exception as e:
            print('[-]Error {} {} '.format(target,str(e)))


def write_info(url,code,title='',server='',type='',x_power_by='',location=''):
    with open('websites_banner.txt','a+') as f:
        f.write('{} {} {} {} {} {} \n'.format(code,url,title,server,type,x_power_by,location))

if __name__ == '__main__':
    try:
        queue = Queue()
        filename = argv[1]
        new_filename = argv[2]
        with open(filename,'r+') as f:
            for url in f:
                url = url.strip()
                if url not in new_targets:
                    new_targets.append(url)
        for new_url  in new_targets:
            queue.put(new_url)
            with open(new_filename,'a+') as f:
                f.write(new_url + '\n')
        while queue.qsize() > 0:
            if activeCount() <= 10:
                Thread(target=get_banner, args=(queue.get(),)).start()
    except IndexError:
        print('Usage:python3 get_banner.py urls.txt new_urls.txt')

 

标签:30x,批量,title,url,req,headers,strip
From: https://www.cnblogs.com/websec80/p/17349076.html

相关文章

  • Django4全栈进阶之路9 url路由设置
    在Django4中,可以在主路由文件中设置和管理子路由。通常,我们会为每个应用程序创建一个子路由文件,以便更好地组织代码和管理路由。以下是Django4中设置主路由和子路由的示例:首先,在主路由文件urls.py中导入子路由,并将其添加到urlpatterns中:#urls.pyfromdjango.urls......
  • 批量替换 MySQL 指定字段中的字段
    批量替换MySQL指定字段中的字符串是数据库应用中很常见的需求,但是有很多初学者在遇到这种需求时,通常都是用脚本来实现;其实,MySQL内置的有批量替换语法,效率也会高很多;批量替换的具体语法是:Code:UPDATE表名SET指定字段=replace(指定字段,’要替......
  • 盘点6个Pandas中批量替换字符的方法
    今日鸡汤朱雀桥边野草花,乌衣巷口夕阳斜。大家好,我是Python进阶者。一、前言前几天在Python最强王者群有个叫【dcpeng】的粉丝问了一个关于Pandas中的问题,这里拿出来给大家分享下,一起学习。想问一下我有一列编码为1,2,3,4的数据,如何将1批量换为“开心”,2批量换为“悲伤”这种字符替换呢......
  • 盘点4种方法用Python批量提取[]括号内的第一个元素
    今日鸡汤葡萄美酒夜光杯,欲饮琵琶马上催。大家好,我是Python进阶者。前言前几天在才哥交流群里边遇到一个叫【上海-数据分析-小粒】的粉丝提了一个小问题,如下:数据如下:咋一看,这个题目倒是也确实不太难,群里提供思路的人也很多,一起来看看吧!思路和实现方法针对这个问题,群里的小伙伴纷纷......
  • JVM调优笔记(一)--Nacos GC引发的服务批量下线问题
    故障背景线上批量发服务下线的告警邮件,偶发nacos连接超时。采用了springbootadmin(以下称sba)进行服务监控。原因分析因为sba服务是基于nacos对其它服务进行监控,所以遇到这个问题,第一怀疑对象是nacos发生问题,但不清楚具体是什么问题。由于服务过一段事件会恢复,所以nacos肯定是......
  • 手把手教你用Python打造一款批量下载视频并能可视化显示下载进度的下载器
    今日鸡汤桃之夭夭,灼灼其华。/1前言/    平时宅在家的我们最爱做的事莫过于追剧了,但是有时候了,网络原因,可能会让你无网可上。这个时候那些好看的电视剧和电影自然是无法观看了,本期我们要讲的就是怎样下载这些视频。/2项目目标/    通过Python程序对所感兴趣的视频进行批量......
  • Mybatis-plus批量操作
    前言使用Mybatis-plus可以很方便的实现批量新增和批量修改,不仅比自己写foreach遍历方便很多,而且性能也更加优秀。但是Mybatis-plus官方提供的批量修改和批量新增都是根据id来修改的,有时候我们需求其他字段,所以就需要我们自己修改一下。一、批量修改在Mybatis-plus的IService......
  • Mysql Mybatis 批量修改数据
    MysqlMybatis批量修改数据MapperIntegerupdateListPO(List<ProjectQuotationItemPO>upateList);方法一:<updateid="updateListPO"><foreachcollection="list"separator=";"item="item">UPDATEpro......
  • 干货分享:用ChatGPT调教批量出Midjourney咒语,出图效率Nice ,附资料。
    Prompts就是AI绘图的核心竞争力。您是不是觉得用Midjourney生成的图不够完美?又让ChatGPT去生成Prompt,然后效果还不理想?其实ChatGPT你给他投喂资料后,经过调教的ChatGPT,生成的Prompt效果会很不错。文末附《一整套MidJourney指令大全》+《ChatGPTprompt指令大全》资料先看测试......
  • URL 正则表达式 实例
    1.获取URL指定参数exportfunctionparseQueryString(name:string,url=location.search){constreg=newRegExp(`(^|[?&])${name}=([^?&]*)(&|$)`,'i');returndecodeURIComponent(reg.exec(url)?.[2]||'');}consturl=http......