def parse_course_table (p, tree, table): courses = [] course_type_path = tree.getpath (table) + "/descendant::a[contains(@class, 'title')]/text()" course_type = tree.xpath(course_type_path)[0] codes_path = tree.getpath (table) + "/descendant::td[contains(@class, 'code')]/a" codes = tree.xpath (codes_path) codes_title_path = tree.getpath (table) + "/descendant::td[contains(@class, 'title')]/a/text()" codes_title = tree.xpath (codes_title_path) if len(codes) != len(codes_title): print ("Error: lengths don't match with codes and codes_title") return [] for i in range (len (codes)): c = Course(codes[i].text) c.type = parse_course_type (course_type) c.name = codes_title[i] c.link = codes[i].get ("href") for e in codes_title[i].getparent().itersiblings(): if e.tag == "span" and e.get ("class") == "comment": for p in e.iterchildren(): if p.tag == "p": c.comment = p.text courses.append (c) return courses