Cacti的流量图爬取

简介: cacti交换机流量图检测工具

Cacti的流量图爬取
Windows环境


from PIL import Image
from io import BytesIO
from docx import Document
from docx.shared import Inches
from bs4 import BeautifulSoup
from http import cookiejar

import datetime
import glob
import shutil
import os
import re
import requests
import urllib

#路径变量
SOURCEPATH=""
Ops=""
INSPECTION=""
MONITOR=""
SHELVES=""

#地点变量
add = "ADDRESS"

#获取cookie
FILENAME = open("cookie.txt", 'w+')
filename = 'cookie.txt'




def GetCookie():
    url = 'url'
    file=urllib.request.urlopen(url)
    #print(file.getcode)
    message = file.info()
    CookieStr = str(message)
    CookieVlue = re.findall(r'Cacti=[a-zA-Z0-9]+',CookieStr)[0]
    print(CookieVlue)
    return CookieVlue

#爬取数据
document = Document()
url='url'
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
    'Cookie':'Cacti=fdsafdsaw32342',
}


for i in (2,3,4,5,6,7,8,9,10,11,34,35,36):
    #目标页面
    for n in (1,3,6):
        #目标目录
        payload1 = {'action':'tree','tree_id':'2','leaf_id':'%s'%i,'page':'%d'%n}

        for m in(350,410,528,472,588,110,170,230,290,1085,1116,1142):
            #流量图ID号

            #正则规则
            Regular1 = '(graph\Simage\Sphp.*local_graph_id=%d.*end=\d+)'%m
            print (Regular1)
            First_Page = requests.get(url,headers=headers,params=payload1)
            print (First_Page.url)

            #清洗数据,获取流量图URL
            plt = re.findall(Regular1,First_Page.text)
            print(plt)
            if len(plt):
                a=(plt[0])
            else:
                True
            JPG_url = ( '<URL>'+ a)
            print( '<URL>'+ a)
            JPG_url_r = JPG_url.replace(';','&')
            print(JPG_url_r)

            #获取图片二进制数据,并保存成doc
            r = requests.get(JPG_url_r,headers=headers)
            image = Image.open(BytesIO(r.content))
            image.save('image%d.bmp'%i)
    document.add_picture('image%d.bmp'%i, width=Inches(6))
document.save('FRALYCHEN.docx')

#复制巡检报告文件并标记日期
T=datetime.datetime.now()

src_file = '00' + add + 'FRALYCHEN.xls'
dst_file = "2019.{}.{}".format(T.month, T.day) + add + 'FRALYCHEN.xls'
shutil.copyfile(SOURCEPATH + src_file,INSPECTION + dst_file)

MonScfile = '00' + add + 'FRALYCHEN.docx'
MonDtfile = "2019.{}.{}".format(T.month, T.day) + add + 'FRALYCHEN.docx'
shutil.copyfile(SOURCEPATH + MonScfile,MONITOR + MonDtfile)

#删除文件
os.remove(SOURCEPATH + MonScfile)
for infile in glob.glob(os.path.join(SOURCEPATH,'*.bmp')):
    os.remove(infile)

#SVN提交
def SvnCommit():
    os.chdir(Ops)
    os.system('svn cleanup')
    r=os.popen('svn st')
    info=r.readlines()
    print(info)

    for line in info:
        line=line.strip('\n').split('       ')
        one=line[0]
        two=line[1]
        print(two)
        if one == '?':
            os.system('svn add %s' % two)
            os.system('svn commit -m %s' % two)
        elif one == '!':
            os.system('svn del %s' %two)
            os.system('svn commit -m "clear"')
SvnCommit()
目录
相关文章
|
3月前
|
数据采集 数据可视化 数据挖掘
Python爬虫实战:抓取网站数据并生成报表
本文将介绍如何使用Python编写简单而高效的网络爬虫,从指定的网站上抓取数据,并利用数据分析库生成可视化报表。通过学习本文内容,读者将能够掌握基本的爬虫技术和数据处理方法,为日后开发更复杂的数据采集与分析工具打下坚实基础。
|
2月前
|
网络协议 Shell 网络安全
实验目的1.编译安装httpd2.优化路径3.并将鲜花网站上传到web服务器为网页目录4.在客户机访问网站http://www.bdqn.com
实验目的1.编译安装httpd2.优化路径3.并将鲜花网站上传到web服务器为网页目录4.在客户机访问网站http://www.bdqn.com
167 0
|
应用服务中间件 定位技术 网络安全
Nginx访问日志接入GrayLog4.2.5并通过GeoIP展现访问者IP的地理位置信息
Nginx访问日志接入GrayLog4.2.5并通过GeoIP展现访问者IP的地理位置信息
411 0
Nginx访问日志接入GrayLog4.2.5并通过GeoIP展现访问者IP的地理位置信息
|
数据采集 JSON 编解码
Python爬虫系列6-百度文库VIP付费数据的抓取
编程难不难?那可不是闹着玩的。不从事这一行的永远不知道这行的艰辛 俗话说的好;爬虫在手天下我有,自从学习了爬虫;看到什么都想盘它一番;直到遇到JS反爬。 不知大家有没有遇到过这种情况;就是你在网上不管是查阅资料也好还是做什么,你会发现其实很多人写的反爬一类的都只给你看结果,你根本不知道这个突破过程是怎么样的,哪怕获取到了代码又有何用;下次再给你一道题,你同样还是不会。你品,你细品...... 我觉得做任何事情一定有在短期内简单可行的方法。学习不应该是苦差事,而应该是快乐的,重要的是找到适合自己的学习方法。师者传道受业解惑!
Python爬虫系列6-百度文库VIP付费数据的抓取
|
JavaScript 前端开发 编解码
网站流量统计实现在原理
1.如何统计停留时间    具体参考“客户统计”相关程序。大致说来,一般有3个表:日表,月表,年表    日表基本设计:IP,进来时间,离开时间,目前时间,停留页面,客户ID(如果登陆),SESSIONID等等    客户访问页面,查询日表有数据没有(SESSIONID),有就更新目前时间和停留页面,没有就新建   判断客户离开时间,可以在前台用JS实现。
2045 0
|
Web App开发 JavaScript PHP