0

I am trying to scrape a table from OECD website about FDI b/w 2005-2021. But when I run the code for the table using html_table, it's returning a list of 0.

I tried the same code with a different table and it worked fine, but this one is not working.

library(rvest)
library(dplyr)

link = "https://data.oecd.org/fdi/fdi-flows.htm#indicator-table"
page = read_html(link)
table = page %>% html_nodes("table.DataTable") %>% html_table()

the above code is returning 'table2: List of 0' and consequently converting it to a table with %>% . [[1]] is not working because it gives the following error:

Error in .[[1]] : subscript out of bounds
Phil
  • 7,287
  • 3
  • 36
  • 66
  • 1
    Those are dynamic javascript-driven tables, not directly accessible through rvest. Though you don't need to scrape that data off the page, the download button links to 2 datasources that you can directly use with `df1 <- readr::read_csv("https://stats.oecd.org/sdmx-json/data/DP_LIVE/.FDIFLOW.../OECD?contentType=csv&detail=code&separator=comma&csv-lang=en")` or `df2 <- readr::read_csv("https://stats.oecd.org/sdmx-json/data/DP_LIVE/.FDIFLOW.OUTWARD.MLN_USD.A/OECD?contentType=csv&detail=code&separator=comma&csv-lang=en&startPeriod=2005&endPeriod=2021")` – margusl Dec 06 '22 at 07:16

0 Answers0