从 coinmarketcap 中抓取数据

Data scraping from coinmarketcap

你好,我正在尝试 抓取 市场 table 在本页末尾“https://coinmarketcap.com/currencies/bitcoin/markets/”。 =12=]

这是我试过的

crpyto_url <- read_html("https://coinmarketcap.com/currencies/bitcoin/markets/")
Exchanges <- crpyto_url %>% 
  html_node(xpath = '//*[@id="__next"]/div/div[2]/div/div[3]/div[2]/div[2]/div/table') %>%
  html_text() %>%
  jsonlite::fromJSON()

这是错误

Error in if (is.character(txt) && length(txt) == 1 && nchar(txt, type = "bytes") < : missing value where TRUE/FALSE needed

我不认为错误是相关的,我认为真正的问题是我不知道如何找到与 table.

相关的 xpath

如果有人设法找到 xpath,能否请您解释一下找到它的过程。或者link一些资源。

谢谢

我.

这可以用 coingecko API 来完成。

url <- "https://api.coingecko.com/api/v3/coins/bitcoin/tickers"
Exchanges <- GET(url)
araw_data <- fromJSON(content(Exchanges, as = "text",encoding = "UTF-8"))
araw_data$tickers$market %>% select(name) %>% pull