我用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']
我该怎么做才能从文本中删除新行。在
谢谢。在