如何从汤中删除转义字符



这是我的代码:

article_edit_page = s.get(article_url, data=payload).text
article_edit_soup = BeautifulSoup(article_edit_page, 'lxml')
    for thing in article_edit_soup.findAll("textarea", {"name":"article"}):
        f.write(str(thing.contents))

给出的输出是:

["rnDallas Area Rapid Transit is adding more officer patrols and increasing the number of security guards as part of its ongoing effort to improve security throughout the system.rnrnAdditional police officers have been assigned to the three transit facilities in the West End section of Downtown Dallas — West End Station"]

我尝试使用.strip()但没有任何变化,''.join()只从第一行中删除转义字符。

我已经提到了这一点,但给了我相同的结果。

编辑:我不想转换我的转义字符,我想删除它们。当我输入get_text而不是contents时,我的输出是:

达拉斯地区捷运公司正在增加更多的警员巡逻队,并增加保安人员的数量,作为其持续努力的一部分,以提高整个系统的安全性。

已向达拉斯市中心西区西区-西区车站的三个交通设施分配了额外的警察

注意两者之间的差距

您可以使用

f.write(str([re.sub('(n|r)', '', e) for e in thing.contents]))

请务必先import re

最新更新