python3提取指定欄位
阿新 • • 發佈:2018-11-02
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)
有問題留言,持續跟新,需要請關注