给定一个字符串,指定开头和结尾的字符串,返回中间包夹的字符串,比如:
content:
75271.com
startStr:
endStr:
返回结果:75271.com
def GetMiddleStr(content,startStr,endStr): startIndex = content.index(startStr) if startIndex>=0: startIndex += len(startStr) endIndex = content.index(endStr) return content[startIndex:endIndex] if __name__=='__main__': print(GetMiddleStr('<div class="a">75271.com</div>','<div class="a">','</div>'))
返回结果
75271.com