使用Python,如何消除从网站上爬取的文本中的尾随空格?

22 浏览
0 Comments

使用Python,如何消除从网站上爬取的文本中的尾随空格?

该问题已经有答案了:

如何从字符串中删除空格?

我正在从网站上爬取文本,使用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). "

admin 更改状态以发布 2023年5月24日
0
0 Comments
itemDesc = itemDesc.replace('  ',' ').replace(',','').replace("''","'").replace("\n","").strip()

(不需要翻译)

0