def find_lec_line(html_lines): """Progress the given iterator until just after the next lecture line, and return the part of the line at the start of the first lecture link. A lecture line contains a lecture link of the form '= 0: return line[idx+1:] return None def split_lecs(line): """This line should start with 'lectures/...' """ end_of_link = line.find('"') link = line[:end_of_link] line = line[end_of_link+1:] next_link = line.find('"lectures/') if next_link == -1: return [link] return [link] + split_lecs(line[next_link+1:]) def find_all_notes(html_lines): """Given an iterator over lines of HTML, find all lecture note links""" result = [] lecture_line = find_lec_line(html_lines) while lecture_line is not None: result += split_lecs(lecture_line) lecture_line = find_lec_line(html_lines) return result