Re: [問題] tuber套件擷取YouTube頻道資訊

看板R_Language作者 (123)時間3年前 (2020/06/23 00:50), 3年前編輯推噓0(005)
留言5則, 1人參與, 3年前最新討論串2/2 (看更多)
原文恕刪 後來我用以下方式可以成功抓到想要的資訊了!! # Get Channel description get_description <- function(id) { get_channel_stats(id)$snippet$description } description <- lapply(data$id, get_description) description_df <- do.call(rbind, lapply(description, data.frame)) # Get Channel region get_Country <- function(id) { get_channel_stats(id)$snippet$country } Country <- lapply(data$id, get_Country) Country_df <- as.data.frame(data.table(Country)) 但以上方式雖然成功抓到資料,有幾個問題也想請教前輩 1. 這邊只列出抓兩種資訊(description & country) 但假設我要抓五個以上資訊的話,只能像上述寫法寫五組嗎? 2. 由於抓出來的資訊有包含英文, 中文, 日文甚至是阿拉伯文在內 我用以下寫法產出的CSV檔,非英文都會出現亂碼或是大量這種<U+25B6> write.table(x = data, file = "Youtube.csv", fileEncoding = "UTF-8", row.names = F) 設定了Sys.setlocale("LC_CTYPE", "Japan")等語系都還是不行 想請問該如何解決? 謝謝各位 補上 sessionInfo() R version 4.0.0 Patched (2020-04-26 r78306) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 system code page: 950 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.250.87.209 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1592844650.A.2B6.html ※ 編輯: iambakr (111.250.87.209 臺灣), 06/23/2020 01:02:00 ※ 編輯: iambakr (111.250.87.209 臺灣), 06/23/2020 01:06:14

06/23 09:38, 3年前 , 1F
1. 你get_description這個function只做一件事(…$snippet$d
06/23 09:38, 1F

06/23 09:38, 3年前 , 2F
escription取值),那為什麼不直接寫就好XD 上篇討論的寫法
06/23 09:38, 2F

06/23 09:38, 3年前 , 3F
還是沒解決嗎?
06/23 09:38, 3F

06/23 09:38, 3年前 , 4F
2. 請參考前面 UTF-8 寫入問題那一篇,用readr套件應該可以
06/23 09:38, 4F

06/23 09:38, 3年前 , 5F
解決你的問題
06/23 09:38, 5F
文章代碼(AID): #1UyE5gAs (R_Language)
文章代碼(AID): #1UyE5gAs (R_Language)