python怎么去除字符串中的换行符,如何在python中删除字符串中的换行符

我用BeautifulSoup来提取一个网站,得到了一个需要的文本。问题是文本中有“\n”字符,需要删除。在

输出文本示例:\nI went to an advance screening of this movie thinking I was about

to\nembark on 120 minutes of cheezy lines, mindless plot, and the kind

of\nnauseous acting that made "The Postman" one of the most

malignant\ndisplays of cinematic blundering of our time. But I was

shocked.\nShocked to find a film starring Costner that appealed to the

soul of\nthe audience. Shocked that Ashton Kutcher could act in such a

serious\nrole. Shocked that a film starring both actually engaged and

captured\nmy own emotions. Not since 'Robin Hood' have I seen this

Costner: full\nof depth and complex emotion. Kutcher seems to have

tweaked the serious\nacting he played with in "Butterfly Effect".

These two actors came into\nthis film with a serious, focused attitude

that shone through in what I\nthought was one of the best films I've

seen this year. No, its not an\nOscar worthy movie. It's not an epic,

or a profound social commentary\nfilm. Rather, its a story about a

simple topic, illuminated in a way\nthat brings that audience to a

higher level of empathy than thought\npossible. That's what I think

good film-making is and I for one am\nthroughly impressed by this

work. Bravo!\n

我尝试了以下方法来删除新行。在

方法1-正则表达式x = review_text.get_text()

y = re.sub(r'(\n)','',x)

方法2-rstrip

^{pr2}$

这两种方法都不适合我。在

当我使用分割时x = review_text.get_text()

print(x.split("\n"),"\n\n")

输出如下['\nI went to an advance screening of this movie thinking I was about

to\nembark on 120 minutes of cheezy lines, mindless plot, and the

kind of\nnauseous acting that made "The Postman" one of the most

malignant\ndisplays of cinematic blundering of our time. But I was

shocked.\nShocked to find a film starring Costner that appealed to

the soul of\nthe audience. Shocked that Ashton Kutcher could act in

such a serious\nrole. Shocked that a film starring both actually

engaged and captured\nmy own emotions. Not since \'Robin Hood\' have

I seen this Costner: full\nof depth and complex emotion. Kutcher

seems to have tweaked the serious\nacting he played with in

"Butterfly Effect". These two actors came into\nthis film with a

serious, focused attitude that shone through in what I\nthought was

one of the best films I\'ve seen this year. No, its not an\nOscar

worthy movie. It\'s not an epic, or a profound social

commentary\nfilm. Rather, its a story about a simple topic,

illuminated in a way\nthat brings that audience to a higher level of

empathy than thought\npossible. That\'s what I think good film-making

is and I for one am\nthroughly impressed by this work. Bravo!\n']

我该怎么做才能从文本中删除新行。在

谢谢。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值