使用python如何去除从网站上刮取的文本中的尾随空格

使用python如何去除从网站上刮取的文本中的尾随空格,python,string,beautifulsoup,Python,String,Beautifulsoup,我正在从一个网站上抓取文本,我正在使用python中的strip函数除去这些换行符和尾随空格,并用空格替换所有逗号。但是它什么都不做 # print(predesc[0].div.p) itemDesc = predesc[0].div.p.text # itemDesc= str(itemDesc).strip("\\t\\n") itemDesc.strip()

我正在从一个网站上抓取文本,我正在使用python中的strip函数除去这些换行符和尾随空格,并用空格替换所有逗号。但是它什么都不做

            # print(predesc[0].div.p)
            itemDesc = predesc[0].div.p.text
            # itemDesc= str(itemDesc).strip("\\t\\n")
            itemDesc.strip()
            itemDesc.strip("\t")
            itemDesc.strip("\n\n")
            itemDesc.replace(",","")











            print(repr(itemDesc))```
output is
"                        Shortcut the learning curve with an all-around board that''s catch-free and easy for boosting confidence anywhere you take it.\n\nSome riders just want to get straight to the fun part. Enjoy a no-fuss feel with the Burton Instigator, a board designed to help accelerate the learning curve and instigate a good time from your first moment on the mountain. The combination of a Flat Top™ bend and Cruise Control convex base keeps things friendly underfoot, creating a catch-free feel that maintains stability and control. The Channel® mounting system gives you the easiest, most adjustable setup with bindings from all major brands (not just Burton''s). "

strip()
返回一个新值…它不会更改原始字符串。您需要类似于
itemDesc=itemDesc.strip()
的内容。为变量指定要删除尾随空格的内容。然后打印出来。谢谢我注意到它确实去掉了空格,但是\n\n没有像从任何其他数据中去掉尾随空格那样被剥离。
itemDesc = itemDesc.replace('  ',' ').replace(',','').replace("''","'").replace("\n","").strip()