python处理crash文件

由于项目需要处理crash文件,crash记录是存储在一张csv表中,具体的内容在网页上,因此需要用python写一个脚本,主要是可以从csv表中抽出crash数据,然后从网上可以通过爬虫爬取数据,这里记录下,以防以后忘记

# -*- coding: cp936 -*-
import urllib2 #网络爬虫库
import csv #excel表库
import time #时间库

crash_data_dict = {}
index = 1

reader = csv.reader(file('C:\Users\zhouwei\Desktop\crash_data.csv', 'rb'))
for line in reader:
        if reader.line_num == 1:
                continue
        if len(line) == 5:
                crash_data_dict[index] = {"id":line[0], "count":line[2], "md5":line[4]}
                index = index + 1

url_prefix = 'http://ip:port/reports/api/v1/reports/'
filename = 'crash_data' + time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())) + '.txt'

for k in crash_data_dict:
        url = url_prefix + crash_data_dict[k]["id"]
        response = urllib2.urlopen(url)
        crash_content = response.read()
#        print crash_content
        fp = open(filename, 'a')
        fp.write("\n-------------------------" + crash_data_dict[k]["count"] + "\n")
        fp.writelines(crash_content)
        fp.close()

由于公司机密,这里就直接将实际ip和port隐匿了

整体处理还是比较简单,这里还是要根据实际项目中crash_data.csv格式来进行处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值