如果您打开此网页,则会出现绿色"导出"按钮:http://mics.unicef.org/surveys
如果在Web浏览器中单击它,则文件surveys_catalogue.csv
开始下载。我的目标是在R。
当我在Chrome中inspect element
时,看起来这个页面有一个request payload
标题,我无法弄清楚如何在R中实现?
答案 0 :(得分:4)
你可能会更好:
library(jsonlite)
library(tibble)
library(dplyr)
res <- GET("http://mics.unicef.org/api/survey")
content(res, as="text") %>%
fromJSON(flatten=TRUE) %>%
as_tibble() %>%
glimpse()
## Observations: 312
## Variables: 11
## $ round <chr> "MICS1", "MICS1", "MICS1", "MICS1", "MICS1",...
## $ region <chr> "Central and Eastern Europe and the Commonwe...
## $ country <chr> "Croatia", "Kyrgyzstan", "Turkey", "Turkmeni...
## $ country_in_filter <chr> "Croatia", "Kyrgyzstan", "Turkey", "Turkmeni...
## $ year <chr> "1996", "1995", "1995", "1995", "1996", "199...
## $ status <chr> "Completed", "Completed", "Completed", "Comp...
## $ reports <list> [<Final, https://mics-surveys-prod.s3.amazo...
## $ archive <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
## $ extra_info <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
## $ dataset.status <chr> "Not available", "Not available", "Not avail...
## $ dataset.url <chr> "", "", "", "", "", "", "", "", "", "", "", ...
相同的数据,但也有更多的数据。
该URL是用于构建顶部过滤器行的内容(该站点发出一些XHR请求来构建表和过滤器行)。 CSV&#34;导出&#34;这是你真正不需要的额外步骤,因为你可以直接获取XHR URL(就像我在这里所做的那样)。