은 프레드릭의 대답에 또 다른 팁을 추가하려면 difflib 모듈의 특히 좋아 해요, 당신은 또한이 하나 검색 엔진 코드와 같은에서 영감을 얻을 수있다 :
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
나는 이들을 결합 된 객체로 그룹화하고 데이터베이스에 추가 할 때 검사를 수행하려고합니다. –