【问题标题】:Error while trying to parse a html table using rvest html_table尝试使用 rvest html_table 解析 html 表时出错
【发布时间】:2019-12-10 14:14:52
【问题描述】:

我正在尝试从此网址读取表格:

https://www.nseindia.com/live_market/dynaContent/live_analysis/most_active_underlyings.htm

library(rvest)
library(magrittr)

url = "https://www.nseindia.com/live_market/dynaContent/live_analysis/most_active_underlyings.htm"
tbl = read_html(url) %>% html_node("table") %>% html_table()

错误信息:

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

【问题讨论】:

    标签: r rvest


    【解决方案1】:

    看起来基础数据可通过this URL 的 GET 请求获得

    要将其放入 R... 使用此

    library(jsonlite)
    tmp <- fromJSON("https://www.nseindia.com/live_market/dynaContent/live_analysis/underlyings/ActiveUnderlyingsValue.json")
    df <- tmp$data
    
    > head(df)
      FO_SYMBOL  VOLUME1   VOLUME2 TOTAL_VOLUME   VALUE1      VALUE2 TOTAL_VALUE UNDERLYINGVALUE
    1 BANKNIFTY 1,36,046 83,23,989    84,60,035 8,521.68 5,23,514.39 5,32,036.07       31,160.35
    2     NIFTY 1,01,176 41,10,138    42,11,314 9,050.23 3,69,056.93 3,78,107.16       11,856.80
    3      SBIN   49,403    75,206     1,24,609 4,722.48    7,455.53   12,178.01          313.20
    4  RELIANCE   15,093    30,744       45,837 1,183.71    2,459.68    3,643.39        1,564.90
    5       TCS   20,578    40,737       61,315 1,044.29    2,139.57    3,183.86        2,016.25
    6 ICICIBANK   21,264    19,857       41,121 1,548.93    1,462.62    3,011.55          529.75
            OP OPENINTEREST
    1 1,824.84     7,75,725
    2 1,349.93    15,54,357
    3   143.40       69,024
    4    27.77     1,29,759
    5    26.17     1,00,669
    6    23.59       99,142
    

    【讨论】:

    • 该代码直到最近才有效。现在我得到这个错误: parse_con(txt, bigint_as_char) 中的错误:词法错误:json 文本中的无效字符。
    • 看起来他们已将其移至不同的子域...试试这个网址:www1.nseindia.com/live_market/dynaContent/live_analysis/…
    • 在域中使用www1 而不是www
    • 我可以通过按F12 使用firefox 中的网络监视器发现这一点。 Chrome 也有类似的实用程序。转到原始站点,按 F12,重新加载站点以重新生成流量并查看 GET 请求。你应该在那里看到这个。 developer.mozilla.org/en-US/docs/Tools/Network_Monitor
    猜你喜欢
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 2013-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多