【发布时间】:2011-04-25 01:11:51
【问题描述】:
基本上,我想每天从 Yahoo! 抓取一些选项数据!金融。我一直以(1)为例来踢轮胎。然而它还没有完全解决,因为我不熟悉 HTML。
(1)Scraping html tables into R data frames using the XML package
作为一个例子,我想抓取并收集以下选项链 http://finance.yahoo.com/q/op?s=MNTA&m=2011-05
这是我到目前为止所尝试的。最后两行不起作用,因为我不清楚我应该寻找什么类。任何帮助都会很棒。谢谢。
library(RCurl)
library(XML)
theurl <- "http://finance.yahoo.com/q/op?s=MNTA&m=2011-05"
webpage <- getURL(theurl)
webpage <- readLines(tc <- textConnection(webpage)); close(tc)
pagetree <- htmlTreeParse(webpage, error=function(...){}, useInternalNodes = TRUE)
tablehead <- xpathSApply(pagetree, "//*/table[@class='yfnc_datamodoutline1']/tr/th", xmlValue)
results <- xpathSApply(pagetree, "//*/table[@class='wikitable sortable']/tr/td", xmlValue)
最后两行没有
【问题讨论】:
标签: xml r web-scraping finance