使用正则findall提取 import re with open ('abc.xml','r') as fr: xmltext = fr.read() CaseId = re.findall(r'.*?<ns4:CaseId>(.*?)</ns4:CaseId>.*?', xmltext)[0]