diff options
Diffstat (limited to 'scripts/convert.py')
-rw-r--r-- | scripts/convert.py | 21 |
1 files changed, 21 insertions, 0 deletions
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]) |