python Excel

#!/usr/bin/env python
#coding:utf-8
"""
  Author:  daozhu --<>
  Purpose: excel
  Created: 2018/2/6
"""
from pyExcelerator import *
import time
from baidu_ip import get_ip

print get_ip('www.tcmjczx.cn')

# excel 第一行数据
excel_headDatas = [u'URL', u'IP', u'IP_Info', u'domain' ,u'CDN', u'WAF', u'Server', u'404', u'DNS_Vuln', u'IIS_Vuln', u'Struts_Vuln']

articles = []
f=open('dict/ll.txt','rU')
for i in f.readlines():
    i = i.strip()
    if get_ip(i):
        print i + str(get_ip(i))
        s = {u'URL':str(i), u'IP': str(get_ip(i)), u'IP_Info':'12', u'domain':'3', u'CDN':'1', u'WAF': '1', 
             u'Server':'qq', u'404':'ww', u'DNS_Vuln':'22', u'IIS_Vuln':'we', u'Struts_Vuln':'eee'}
        articles.append(s)

#articles =[
    #{u'URL':u'www.baidu.com',
     #u'IP':u'cheduzi',
     #u'IP_Info':'cheduzi1',
     #u'domain':u'cheduzi',
     #u'CDN' : '2',
     #u'WAF' : '3',
     #u'Server' : '4',
     #u'404' : '5',
     #u'DNS_Vuln' : '3',
     #u'IIS_Vuln' : '5',
     #u'Struts_Vuln' : '6'},

#]


# 定义excel操作句柄
excle_Workbook = Workbook()
excel_sheet_name = time.strftime('%Y-%m-%d')
excel_sheet = excle_Workbook.add_sheet(excel_sheet_name)
index = 0

#标题
for data in excel_headDatas:
    excel_sheet.write(0, index, data)
    index += 1

index = 1
#内容
for article in articles:
    colIndex = 0
    for item in excel_headDatas:
        excel_sheet.write(index, colIndex, article[item])
        colIndex += 1
    index += 1
    
    
#保存test.xlsx到当前程序目录
excle_Workbook.save('test.xls')

f.close()

image.png

你可能感兴趣的:(python Excel)