【问题标题】:How to scrape tables from https sites using R如何使用 R 从 https 站点抓取表格
【发布时间】:2016-02-16 17:05:11
【问题描述】:

我想使用 https 从网站上抓取表格。我想要处理未来合约细节的表格(合约、到期、手数、价格、NRML 保证金、IS 保证金)

我为从该站点获取表格而编写了这段代码,但它显示了两个错误。

1) 函数错误(类型、msg、asError = TRUE): 连接零端口 80 失败:连接被拒绝

2) 警告消息:XML 内容似乎不是 XML: 'https://zerodha.com/margin-calculator/Futures/'

library(XML)
library(RCurl)
zero='https://zerodha.com/margin-calculator/Futures/'
zero<-getURL("zero")
#Error in function (type, msg, asError = TRUE)  : 
#  Failed to connect to zero port 80: Connection refused
zero.table=readHTMLTable(zero)
#Warning message:
#XML content does not seem to be XML: 'https://zerodha.com/margin-calculator/Futures/' 

【问题讨论】:

    标签: xml r rcurl


    【解决方案1】:

    我会使用httr

    library("httr")
    library("rvest")
    zero <- httr::GET("https://zerodha.com/margin-calculator/Futures/zero")
    tables <- rvest::html_table(content(zero))
    head(tables[[1]])
    
    Product type                       Name
        1         NRML                     Normal
        2          MIS Margin Intraday Square off
        3           CO                Cover Order
                                                                                                                                                                                                                          Used for
        1 Overnight/positional or intraday trade futures using NRML with margins mentioned below. Once a position taken as NRML, it can be held till the expiry provided the requesite NRML margin present in the trading account.
        2                                                                    Intraday trade using MIS for additional leverage (40% of NRML margin) between 9:15 AM and 3:20 PM. All open MIS positions get squared off at 3:20 PM.
        3                                                                                                                                                Please use the Bracket Order & Cover Order calculator for CO calculations
    

    【讨论】:

      猜你喜欢
      • 2016-05-25
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多