为了另一个提示添加到弗雷德里克的答案,你也可以得到来自搜索引擎如代码,像这样的启发:
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
来源和更多信息:http://www.zackgrossbart.com/hackito/search-engine-python/
问候,
最大
你想得到什么结果?你想要在整个字符串中查找所有这些变体? – JMax
我想将这些组合成一个组合对象,并在添加到数据库时执行检查。 –