【发布时间】:2013-01-01 04:53:04
【问题描述】:
我正在使用 tweepy 收集随机推文, 我想过滤掉非字母数字的推文。
但为了进行检查,我首先需要将推文转换为字符串。 例如,
from tweepy import StreamListener
....
class sListener(StreamListener):
def on_status(self,status):
....
text = str(status.text)
if not isAlphanumeric(text):
......
但是,使用 str() 将推文转换为字符串本身会导致错误,如果推文是非 ascii 并带有以下消息:
UnicodeEncodeError: 'ascii' codec can't encode character
所以我陷入了一个循环,我需要转换为字符串来过滤非ascii,但由于非ascii,我无法转换为字符串......
我什至不知道推文是什么数据类型...
谁能帮帮我?
【问题讨论】:
-
你试过了吗? (stackoverflow.com/a/1207479/1984421)
-
如果您不想要非 ascii 推文,为什么不跳过那些使用
str()无法转换的推文?
标签: python twitter unicode tweets tweepy