-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProwlerHTML2CSV.py
More file actions
44 lines (36 loc) · 1.34 KB
/
ProwlerHTML2CSV.py
File metadata and controls
44 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# AI WAS USED IN THE MAKING OF THIS PROGRAM. AI USED: ChatGPT-4o
# NAME:
# ProwlerHTML2CSV
# CREATED BY:
# Garrett Greathouse
import bs4
from bs4 import BeautifulSoup
import csv
import glob
# Open Prowler HTML output
html_file_list = glob.glob("prowler-output-*.html")
html_file_name = html_file_list[html_file_list.index(max(html_file_list))] # Gets most recent file by name
with open(html_file_name, "r", encoding="utf-8") as file:
html_file = file.read()
# Parse HTML
soup = BeautifulSoup(html_file, "html.parser")
# Grabs table with data
table = soup.find(id="findingsTable")
# TESTING PURPOSES ONLY
# with open("bs4-test.html", "w", encoding="utf-8") as output_file:
# output_file.write(table.prettify())
# Extract headers
headers = [th.get_text(strip=True) for th in table.find_all("th")]
# Extract data
rows = []
for tr in table.find_all("tr", class_="table-danger")[1:]:
cells = [td.get_text(strip=True) for td in tr.find_all("td")]
if cells:
rows.append(cells)
# Transfer data to new CSV
output_file = "prowler-csv-output.csv"
with open(output_file, "w", newline='', encoding="utf-8") as csv_file:
writer = csv.writer(csv_file)
writer.writerow(headers) # Header row
writer.writerows(rows) # Date rows
print(f"Data has been successfully written to {output_file}")