X-Git-Url: https://git.armaanb.net/?p=lightcards.git;a=blobdiff_plain;f=lightcards%2Fparse.py;h=ea3468d66bfdca5f898431ce3a8d6743712b405f;hp=a447485e4b046f4ab16bc67b251c8b140a41cba5;hb=08e393b41878e67e92e1031cfe69d909df453b60;hpb=61808c327216bcf1973ace53f9bbb679bd1b9309 diff --git a/lightcards/parse.py b/lightcards/parse.py index a447485..ea3468d 100644 --- a/lightcards/parse.py +++ b/lightcards/parse.py @@ -25,11 +25,18 @@ def parse_html(html): soup = BeautifulSoup(html, "html.parser").find("table") outp = [] - for x in soup.find_all("tr"): - outp.append(Card([clean_text(y) for y in x.find_all("td")[:2]])) + try: + for x in soup.find_all("tr"): + outp.append(Card(tuple([clean_text(y) for y in x.find_all("td")]))) + except AttributeError: + sys.exit("lightcards: No table found") + + ths = soup.find_all("th") + if not len(ths) in [1, 2]: + sys.exit("lightcards: Headings malformed") # Return a tuple of nested lists - return ([clean_text(x) for x in soup.find_all("th")][:2], outp[1:]) + return ([clean_text(x) for x in ths], outp[1:]) def main(file):