-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_report.py
More file actions
35 lines (28 loc) · 1 KB
/
csv_report.py
File metadata and controls
35 lines (28 loc) · 1 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
import csv
def write_csv_report(page_data, filename="report.csv"):
if not page_data:
print("No data to write to CSV")
return
with open(filename, "w", newline="", encoding="utf-8") as csvfile:
fieldnames = [
"page_url",
"h1",
"first_paragraph",
"outgoing_link_urls",
"image_urls",
]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for page in page_data.values():
outgoing_links_str = ";".join(page["outgoing_links"])
image_urls_str = ";".join(page["image_urls"])
writer.writerow(
{
"page_url": page["url"],
"h1": page["h1"],
"first_paragraph": page["first_paragraph"],
"outgoing_link_urls": outgoing_links_str,
"image_urls": image_urls_str,
}
)
print(f"Report written to {filename}")