From a52240fe4f9a160f3fcd65217b7f7307fa13e820 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 30 May 2019 16:00:57 +0100 Subject: Add conversion script --- scripts/convert.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 scripts/convert.py (limited to 'scripts/convert.py') diff --git a/scripts/convert.py b/scripts/convert.py new file mode 100644 index 0000000..e179774 --- /dev/null +++ b/scripts/convert.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import sys +from bs4 import BeautifulSoup +import csv + +def main(file_): + with open(file_, "r") as f: + file_contents = f.read() + + soup = BeautifulSoup(file_contents) + table = soup.select_one("table") + headers = [th.text.encode("utf-8") for th in table.select("tr th")] + + with open("out.csv", "w") as f: + wr = csv.writer(f) + wr.writerow(headers) + wr.writerows([[td.text.encode("utf-8") for td in row.find_all("td")] for row in table.select("tr + tr")]) + +if __name__ == '__main__': + main(sys.argv[1]) -- cgit