""" Program that grabs the specific lecture URLs from the CS10 course home page """ # David Kauchak # 11/8/2011 import urllib course_page = "http://www.cs.middlebury.edu/~dkauchak/classes/cs150/" def get_note_urls(course_page): """ Get the lecture URLs available from the course web page and return them in a list """ web_page = urllib.urlopen(course_page) urls = [] # all of the urls for lectures, start with "lectures/" search_line = "lectures/" for line in web_page: if search_line in line: begin_index = line.find(search_line) end_index = line.find('"', begin_index) urls.append(course_page + line[begin_index:end_index]) return urls def write_list_to_file(some_list, output_file): """Write out all of the contents of the list to the file""" out = open(output_file, "w") out.write("Lecture notes for CS150\n\n") for item in some_list: out.write(item + "\n") out.close() # get the lecture urls lecture_urls = get_note_urls(course_page) # print them out to the file write_list_to_file(lecture_urls, "lectures.txt")