当前位置:   article > 正文

python3提取指定字段_python 抓固定字段

python 抓固定字段

python3提取指定字段,工具代码一篇,阅读大约时长三分钟

  1. def txt_wrap_by(start_str, end, html):
  2. #提取俩个字符间的东西
  3. start = html.find(start_str)
  4. if start >= 0:
  5. start += len(start_str)
  6. end = html.find(end, start)
  7. if end >= 0:
  8. return html[start:end].strip()
  9. def txt_wrap_by2(start_str,end_str,html):
  10. #通过切片提取指定字符
  11. start=html.find(start_str)
  12. end = html.find((end_str),len(end_str)+start)
  13. return html[start:end]
  14. # start = s.find('image_url')
  15. # end = s.find('>', len('image_url')+start)
  16. # s[start:end]
  17. if __name__=="__main__":
  18. filename="C:/Users/Desktop/info.2018"
  19. f1 = open(filename,encoding='utf-8')
  20. newDate=''
  21. while True:
  22. line=f1.readline()
  23. if (not line):
  24. break
  25. newDate+=txt_wrap_by2("<title:",">",line)
  26. print(newDate)

有问题留言,持续跟新,需要请关注 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/367807?site
推荐阅读
相关标签
  

闽ICP备14008679号