en(excel)):
worksheet.write(row,col,excel[i][0])
worksheet.write(row,col+1,excel[i][1])
worksheet.write(row,col+2,excel[i][2])
worksheet.write(row,col+3,excel[i][3])
worksheet.write(row,col+4,excel[i][4])
worksheet.write(row,col+5,excel[i][5])
worksheet.write(row,col+6,excel[i][6])
worksheet.write(row,col+7,excel[i][7])
worksheet.write(row,col+8,excel[i][8])
worksheet.write(row,col+9,excel[i][9])
worksheet.write(row,col+10,excel[i][10])
worksheet.write(row,col+11,excel[i][11])
worksheet.write(row,col+12,excel[i][12])
worksheet.write(row,col+13,excel[i][13])
worksheet.write(row,col+14,excel[i][14])
row += 1
workbook.close()
def main():
#调用漏洞列表函数并获得漏洞链接列表
begin = datetime.datetime.now()
global holes_lists
holes_lists=[]
j = 1
page_count = sys.argv[3]
page_count = int(page_count)
start_time = sys.argv[1]
end_time = sys.argv[2]
while j<=page_count:
try:
holes_url = 'http://cnnvd.org.cn/web/vulnerability/queryLds.tag?pageno=%d&repairLd='%j
holes_url_list(holes_url,start_time,end_time)
print("已完成爬行第%d页"%j)
print('\n')
time.sleep(2)
j+=1
except:
print('爬取失败,等待5秒后重新爬取。')
time.sleep(5)
#调用漏洞信息函数并爬取漏洞信息
holes_result_lists = []
a=0
while a < len(holes_lists):
try:
holes_data(holes_lists[a])
holes_result_lists.append(holes_result_list)
a+=1
print("完成爬行第%d个漏洞信息"%a)
time.sleep(1)
except:
print('爬取失败,等待5秒后重新爬取。')
time.sleep(5)
#漏洞信息写入excel
holes_excel(holes_result_lists)
#爬行结束
end = datetime.datetime.now()
total_time = end - begin
print ('漏洞信息爬取结束')
print ('应该爬行漏洞数量: ',len(holes_lists))
print ('爬行时间: ',total_time)
if __name__ == '__main__':
main()
|