import codecs
FileName = r'c:\ls\1'
#KeyStr = input("the key string: ")
KeyStr = '<dd class="info"><span>执业证号:'
FoundFlag = False
#用utf-8格式打开文件
#用utf-8格式打开文件
FileObj = codecs.open(FileName, 'r', 'utf-8')
LineTemp = FileObj.readline()
while LineTemp:
# print(LineTemp)
# print(KeyStr)
# zc = LineTemp.find(KeyStr)
if LineTemp.find(KeyStr) > 0:
FoundFlag = True
print("*************************")
print("the line is: " + LineTemp, end='')
print("*************************")
LineTemp = FileObj.readline()
# break
else:
LineTemp = FileObj.readline()
FileObj.close()
if FoundFlag == False:
print("Not found the string!")
本文介绍了一个使用Python实现的简单脚本,该脚本可以用来搜索指定文件中是否包含特定字符串。通过读取文件并检查每行内容,如果找到目标字符串则会输出包含该字符串的整行内容。

被折叠的 条评论
为什么被折叠?



