我正在使用 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,我无法转换为字符串......
我什至不知道推文是什么数据类型...
有人可以帮我吗?