file = open(‘a’,'r')
content = file.read()
post = content.find(keyword)
if post != -1:
content = content[:post+len(keyword)]+str+content[post+len(keyword):]
file = open(‘a’,'w')
file.write(content)
file.close()
txt = './out.txt'
aim = '点击量'
addon = 'goal\n'
with open(txt, 'r', encoding='utf-8') as f:
s = f.readlines()
with open(txt, 'w', encoding='utf-8') as f:
for i in s:
f.writelines(i)
if aim in i:
f.writelines(addon)