我试图抓取一个非常'右侧'的网站来进行关于仇恨和种族主义检测的研究,所以我的测试内容可能会受到攻击。使用NLTK编码问题
我试图删除一些停用词和标点符号在Python中,我使用NLTK,但我遇到了一个编码问题...我使用Python 2.7和数据来自一个文件,我填写文章从网站我爬到:
stop_words = set(nltk.corpus.stopwords.words("english"))
for key, value in data.iteritems():
print type(value), value
tokenized_article = nltk.word_tokenize(value.lower())
print tokenized_article
break
和输出看喜欢:(我加...缩短样品)
<type 'str'> A Negress Bernie ... they’re not going to take it anymore.
['a', 'negress', 'bernie', ... , 'they\u2019re', 'not', 'going', 'to', 'take', 'it', 'anymore', '.']
我不明白为什么有这个“\ u2019”那不应该在那里。如果有人可以告诉我如何驾驶它。我试图用UTF-8编码,但我仍然遇到同样的问题。
'\ u2019'是unicode符号[右单引号](http://unicode.org/cldr/utility/character.jsp?a=2019)。如果你没有太多不同的问题字符,你可以简单地[修复你的字符串](http://stackoverflow.com/questions/24358361/removing-u2018-and-u2019-character) – alexis