在R中从网上抓取表格数据

时间:2017-05-15 07:08:46

标签: r

我正试图从R

中的以下链接中提取表格
library(rvest)
library(XML)
library(stringr)
library(tidyr)

url <- "http://www.moneycontrol.com/stocks/hist_index_result.php?indian_indices=9"
nifty_index <- url %>%
read_html() %>%
html_nodes(xpath='//*[@id="mc_mainWrapper"]/div[2]/div/div[3]/div[4]/table') %>%
html_table()
nifty_index <- nifty_index[[1]]


Error 

Error in matrix(NA_character_, nrow = n, ncol = maxp) : 
invalid 'ncol' value (too large or NA)
In addition: Warning messages:
1: In max(p) : no non-missing arguments to max; returning -Inf
2: In matrix(NA_character_, nrow = n, ncol = maxp) :
NAs introduced by coercion to integer range

问题是当我点击链接时http://www.moneycontrol.com/stocks/hist_index_result.php?给我一个空白页面。从此链接http://www.moneycontrol.com/stocks/histstock.php

填写索引的日期范围后,将生成HTML表格

我如何在R?中做到这一点?

0 个答案:

没有答案