从推文中获取文本 [英] Getting Text From Tweets

查看:39
本文介绍了从推文中获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个 csv 文件(我之前下载过)中读取我的推文,但遇到了一些问题:

I am tring to read my tweets from a csv file (which I have downloaded previously), and I am having some problems:

sia.list <- searchTwitter('#singaporeair', n=10, since=NULL, until=NULL, cainfo="cacert.pem")  
sia.df = twListToDF(sia.list)  
write.csv(sia.df, file='C:/temp/siaTweets.csv', row.names=F)

我正在尝试从列表中提取文本,问题出在下面的第三行:

I am trying to extract the text from the list and the problems is with the third line below:

sia.df <- read.csv(file=paste(path,"siaTweets.csv",sep="")) 
sia.list <- as.list(t(sia.df))
sia_txt = sapply(sia.list, function(x) x$getText())

控制台输出:

   > sia.list <- as.list(t(sia.df))
   > sia_txt = sapply(sia.list, function(x) x$getText())
    Error in x$getText : $ operator is invalid for atomic vectors

推荐答案

如果你想从 csv 文件中读取文本,你所要做的就是:sia_txt <- sia$text(文本是存储文本的列的名称.)

If you want to read the text from a csv file , all you have to do is : sia_txt <- sia$text (text being the name of the column in which your text is stored.)

您在 saaply 中使用的 x$getText 是一种 method 仅适用于作为 searchTwitter 的结果的列表().因此,您不能将 DF 转换回 List 并使用 getText.例如做:

the x$getText you've used in saaply is a method available only to lists which come as result of searchTwitter(). Hence you cannot convert a DF back to List and use getText. For e.g. do:

xyz <- searchTwitter("#xyz", n = 100)

str(xyz)

您将看到适用的方法列表.类似的东西:

You will see a list of methods applicable. something like:

$ :Reference class 'status' [package "twitteR"] 有 17 个字段..$ text : chr "RT @BET: \"谁还爱黑人女人?\" ~ 观看昨晚的#BeingMaryJane 在这里:\nhttp://t.co/xiUho1FVQi http://t.co/"|__截断__..$ 收藏夹:logi FALSE..$ 最喜欢的计数:num 0..$ 回复ToSN : chr(0)..$ 创建:POSIXct[1:1],格式:2015-03-11 13:28:01"..$ 截断:logi FALSE..$ 回复ToSID : chr(0)..$ id : chr "575649378062434304"..$ replyToUID : chr(0)..$ statusSource : chr "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>"..$ screenName : chr "kookie_kay"..$ retweetCount : num 20..$ isRetweet : logi TRUE

和 51 个方法,其中 39 个可能相关:.. getCreated, getFavoriteCount, getFavorited, getId, getIsRetweet, getLatitude, getLongitude, getReplyToSID,.. getReplyToSN、getReplyToUID、getRetweetCount、getRetweeted、getRetweeters、getRetweets、getScreenName、.. getStatusSource, **getText**, getTruncated, getUrls, 初始化

注意 getText.

这篇关于从推文中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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