How do i get rid of all the smart quotes while par

2019-07-18 15:05发布

This is my code :

name = namestr.decode("utf-8")

name.replace(u"\u2018", "").replace(u"\u2019", "").replace(u"\u201c","").replace(u"\u201d", "")

This doesn't seem to work . I still find &ldquo , &rdquo etc in my text. Also this text has been parsed using beautiful soup

1条回答
手持菜刀,她持情操
2楼-- · 2019-07-18 15:56

Replace the last line of your code with this one:

name = name.replace(u"\u2018", "").replace(u"\u2019", "").replace(u"\u201c","").replace(u"\u201d", "")

The replace method returns a modified string but it does not affect the sting you call it on so you have to assign the return value to the variable as above.

查看更多
登录 后发表回答