print "HTTP ERROR EXCEPTION" continue except urllib2.URLError, e: print "URL ERROR EXCEPTION" continue except error, e: print "EXCEPTION" continue if (page == None): print("error opening: " + "http://moneycentral.msn.com/companyreport?symbol=" + ticker) else: s = BeautifulSoup(page) s = s.find('h1', attrs={"class": "h1a"}) s = s.text companyName = s.partition(":")[0] print("Company Name: " + companyName + '\n') ticker = ticker.partition("\n")[0] newFile.write(ticker + ":" + companyName + "\n") openFile.close() newFile.close() def createCompanyMap(path, fileName): openFile = open(path + fileName, 'r') lines = openFile.readlines() openFile.close() companyMap = dict({}) for line in lines: partition = line.partition(":") companyMap[partition[0]] = partition[2]