To add another review to Fredrikβs answer, you can also get inspiration from search engines like code like this one:
def dosearch(terms, searchtype, case, adddir, files = []): found = [] if files != None: titlesrch = re.compile('>title<.*>/title<') for file in files: title = "" if not (file.lower().endswith("html") or file.lower().endswith("htm")): continue filecontents = open(BASE_DIR + adddir + file, 'r').read() titletmp = titlesrch.search(filecontents) if titletmp != None: title = filecontents.strip()[titletmp.start() + 7:titletmp.end() - 8] filecontents = remove_tags(filecontents) filecontents = filecontents.lstrip() filecontents = filecontents.rstrip() if dofind(filecontents, case, searchtype, terms) > 0: found.append(title) found.append(file) return found
Source and additional information: http://www.zackgrossbart.com/hackito/search-engine-python/
Hi,
Max
source share