0

我正在尝试抓取一个选项表:

http://www.cmegroup.com/trading/metals/base/copper_quotes_settlements_options.html

我试过了:

library(XML)
options.cu<-readHTMLTable("http://www.cmegroup.com/trading/metals/base/copper_quotes_settlements_options.html",stringsAsFactors = FALSE)
options.cu

但我只是得到:

$table_under_bluebar V1 V2 V3 1 交易日期类型到期

并且表中没有数据。我会很感激你的帮助。

4

1 回答 1

1

该表是使用 javascript 动态创建的。您可以检查流量以查看是否可以找到供稿。这样做你会注意到以下网址:

http://www.cmegroup.com/CmeWS/mvc/xsltTransformer.do?xlstDoc=/XSLT/da/DailySettlement.xsl

这需要一个 url 作为参数,表示产品线等。例如:

http://www.cmegroup.com/CmeWS/mvc/xsltTransformer.do?xlstDoc=/XSLT/da/DailySettlement.xsl&url=/da/DailySettlement/V1/DSReport/ProductCode/HX/FOI/OOF/EXCHANGE/XCEC/Underlying/HG/ProductId/797

将获得可能具有产品 id 797 的铜选项表。可以通过指定参数添加其他参数:

http://www.cmegroup.com/CmeWS/mvc/xsltTransformer.do?xlstDoc=/XSLT/da/DailySettlement.xsl&url=/da/DailySettlement/V1/DSReport/ProductCode/HX/FOI/OOF/EXCHANGE/XCEC/Underlying/HG/ProductId/797?tradeDate=04/17/2013&monthYear=null&optionTypeName=Daily&optionType=AME

您应该能够使用此提要获取相关数据:

xmlD <- "http://www.cmegroup.com/CmeWS/mvc/xsltTransformer.do?xlstDoc=/XSLT/da/DailySettlement.xsl&url=/da/DailySettlement/V1/DSReport/ProductCode/HX/FOI/OOF/EXCHANGE/XCEC/Underlying/HG/ProductId/797"

library(XML)
options.cu <- readHTMLTable(xmlD,stringsAsFactors = FALSE)
str(options.cu)
#List of 1
# $ DailySettlementTable:'data.frame':  337 obs. of  10 variables:
#  ..$ V1 : chr [1:337] "Daily Settlements for Copper American Options (FINAL)Trade Date: 04/18/2013" "Strike" "025" "050" ...
#  ..$ V2 : chr [1:337] NA "Type" "Call" "Call" ...
#  ..$ V3 : chr [1:337] NA "Open" "-" "-" ...
#  ..$ V4 : chr [1:337] NA "High" "-" "-" ...
#  ..$ V5 : chr [1:337] NA "Low" "-" "-" ...
#  ..$ V6 : chr [1:337] NA "Last" "-" "-" ...
#  ..$ V7 : chr [1:337] NA "Change" "+.0170" "+.0170" ...
#  ..$ V8 : chr [1:337] NA "Settle" "2.9545" "2.7045" ...
#  ..$ V9 : chr [1:337] NA "EstimatedVolume" "-" "-" ...
#  ..$ V10: chr [1:337] NA "Prior DayOpen Interest" "-" "-" ...
于 2013-04-19T08:13:04.807 回答