gpt4 book ai didi

r - R中非UTF-8和ASCII字符twitteR包的问题

转载 作者:行者123 更新时间:2023-12-04 12:51:10 24 4
gpt4 key购买 nike

在之前的一个问题中,我询问了有关使用 R 中的 twitteR 包从 Haaretz Twitter 提要 (@haaretzcom) 下载大量 Twitter 关注者(及其位置、创建日期、关注者数量等)的问题(参见 Work around rate limit for extracting large list of user information using twitteR package in R )。 Twitter 提要有超过 90,000 个关注者,我可以使用下面的代码下载完整的关注者列表。

   require(twitteR)
require(ROAuth)
#Loading the Twitter OAuthorization
load("~/Dropbox/Twitter/my_oauth")

#Confirming the OAuth
registerTwitterOAuth(my_oauth)

# opening list to download
haaretz_followers<-getUser("haaretzcom")$getFollowerIDs(retryOnRateLimit=9999999)

for (follower in haaretz_followers){
Sys.sleep(5)
haaretz_followers_info<-lookupUsers(haaretz_followers)

haaretz_followers_full<-twListToDF(haaretz_followers_info)

#Export data to csv
write.table(haaretz_followers_full, file = "haaretz_twitter_followers.csv", sep=",")
}

该代码用于提取许多用户。但是,每当我点击某个用户时,我都会收到以下错误:
Error in twFromJSON(out) :
RMate stopped at line 51
Error: Malformed response from server, was not JSON.
RMate stopped at line 51
The most likely cause of this error is Twitter returning a character which
can't be properly parsed by R. Generally the only remedy is to wait long
enough for the offending character to disappear from searches (e.g. if
using searchTwitter()).
Calls: twListToDF ... lookupUsers -> lapply -> FUN -> <Anonymous> -> twFromJSON
Execution halted

即使我在 twitteR 包之后加载 RJSONIO 包,我也遇到了这个问题。从做一些研究来看,twitteR 和 RJSONIO 包在解析非 UTF-8 或 ASCII 字符(阿拉伯语等)时似乎存在问题 http://lists.hexdump.org/pipermail/twitter-users-hexdump.org/2013-May/000335.html .有没有办法在我拥有的代码中简单地忽略非 UTF-8 或 ASCII 并仍然提取所有关注者信息?任何帮助将非常感激。

最佳答案

有一个包更新 (1.1.7),解决了这个问题。见:https://github.com/geoffjentry/twitteR/blob/master/NEWS

关于r - R中非UTF-8和ASCII字符twitteR包的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16574980/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com