我如何摆脱所有的智能报价在分析一个网页? [英] How do i get rid of all the smart quotes while parsing a web page?

查看:212
本文介绍了我如何摆脱所有的智能报价在分析一个网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code:

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

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

这似乎并没有工作。我仍然觉得&放大器; ldquo &放大器; rdquo 等在我的文字。另外这个文本已使用美丽的汤解析

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

推荐答案

这一个替换您的code的最后一行:

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.

这篇关于我如何摆脱所有的智能报价在分析一个网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆