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编写的简单脚本,该脚本可以查找指定文本并打印包含该文本的行。通过读取指定路径下的文件并搜索关键词,此脚本能够帮助用户快速定位到含有特定字符串的内容。

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



