无法使用rvest和Selector小工具从Morningstar中抓取财务数据

时间:2018-06-26 02:59:23

标签: r web-scraping css-selectors finance rvest

第一次尝试从Morningstar的网站上抓取一些财务数据。

具体来说,我正在尝试抓取以下公司的“每股自由现金流”数据:Hongkong Land Holdings

我已经使用选择器小工具突出显示了我想要的数据。以下屏幕截图显示了我的工作。

Hongkong Land Selector Gadget

我尝试使用以下R脚本获取每股自由现金流数据。但是,从html_nodes函数返回的列表是0列表。我尝试使用Selector Gadget的css以及xpath。两种方法均未取得理想的结果。

library(rvest)

url <- "http://financials.morningstar.com/ratios/r.html?t=H78"

webpage <- read_html(url)

FCF_per_share <- html_nodes(webpage, css = "#i90 , tr:nth-child(28) td, :nth-child(7) :nth-child(11) :nth-child(6) :nth-child(5) :nth-child(3) td:nth-child(4)")

FCF_per_share <- html_nodes(webpage, xpath = "//*[(@id = "i90")] | //tr[(((count(preceding-sibling::*) + 1) = 28) and parent::*)]//td//*[(((count(preceding-sibling::*) + 1) = 7) and parent::*)]//*[(((count(preceding-sibling::*) + 1) = 11) and parent::*)]//*[(((count(preceding-sibling::*) + 1) = 6) and parent::*)]//*[(((count(preceding-sibling::*) + 1) = 5) and parent::*)]//*[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]//td[(((count(preceding-sibling::*) + 1) = 4) and parent::*)]")

我尝试查看上面的网页变量。它是2的列表。当我尝试在webpage变量上使用方括号时,得到以下结果(不确定其含义以及是否正确):

webpage[[1]]
<pointer: 0x07928060>
webpage[[2]]
<pointer: 0x0778adc8>

非常感谢帮助。谢谢!

0 个答案:

没有答案
相关问题