python用BeautifulSoup解析源码时,去除空格及换行符

一、去除空格

  strip()

  1.  
    " xyz ".strip() # returns "xyz"
  2.  
    " xyz ".lstrip() # returns "xyz "
  3.  
    " xyz ".rstrip() # returns " xyz"
  4.  
    " x y z ".replace(' ', '') # returns "xyz"
  5.  
     

二、替换 replace("space","")

  用replace("\n", ""),后边的串替换掉前边的

posted @ 2019-09-05 17:16  不夜男人  阅读(4719)  评论(0编辑  收藏  举报