The*_*ger 2 python beautifulsoup smart-quotes nltk
这是我的代码:
name = namestr.decode("utf-8")
name.replace(u"\u2018", "").replace(u"\u2019", "").replace(u"\u201c","").replace(u"\u201d", "")
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用。我仍然在我的文本中找到&ldquo,&rdquo等。此外,此文本已使用 Beautiful Soup 进行解析。
用下面的代码替换最后一行:
name = name.replace(u"\u2018", "").replace(u"\u2019", "").replace(u"\u201c","").replace(u"\u201d", "")
Run Code Online (Sandbox Code Playgroud)
该replace方法返回一个修改后的字符串,但它不会影响您调用它的字符串,因此您必须将返回值分配给上述变量。
| 归档时间: |
|
| 查看次数: |
3493 次 |
| 最近记录: |