python3提取指定字段,工具代码一篇,阅读大约时长三分钟
def txt_wrap_by(start_str, end, html): #提取俩个字符间的东西 start = html.find(start_str) if start >= 0: start += len(start_str) end = html.find(end, start) if end >= 0: return html[start:end].strip() def txt_wrap_by2(start_str,end_str,html): #通过切片提取指定字符 start=html.find(start_str) end = html.find((end_str),len(end_str)+start) return html[start:end] # start = s.find('image_url') # end = s.find('>', len('image_url')+start) # s[start:end] if __name__=="__main__": filename="C:/Users/Desktop/info.2018" f1 = open(filename,encoding='utf-8') newDate='' while True: line=f1.readline() if (not line): break newDate+=txt_wrap_by2("<title:",">",line) print(newDate)
有问题留言,持续跟新,需要请关注