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(" ", ""),后边的串替换掉前边的

原文地址:https://www.cnblogs.com/valorchang/p/11468380.html