无法使用rvest和选择器小工具从晨星获取财务数据
第一次试图从晨星的网站上搜集一些财务数据 具体而言,我正试图获取以下公司的每股自由现金流数据: 我使用了选择器小工具来突出显示我想要的数据。下面的屏幕截图显示了我所做的 我尝试使用下面的R脚本来获取每股自由现金流数据。但是,从无法使用rvest和选择器小工具从晨星获取财务数据,r,web-scraping,css-selectors,finance,rvest,R,Web Scraping,Css Selectors,Finance,Rvest,第一次试图从晨星的网站上搜集一些财务数据 具体而言,我正试图获取以下公司的每股自由现金流数据: 我使用了选择器小工具来突出显示我想要的数据。下面的屏幕截图显示了我所做的 我尝试使用下面的R脚本来获取每股自由现金流数据。但是,从html\u节点函数返回的列表是一个0的列表。我尝试过使用选择器小工具中的css以及xpath。这两种方法都没有得到预期的结果 library(rvest) url <- "http://financials.morningstar.com/ratios/r.ht
html\u节点
函数返回的列表是一个0的列表。我尝试过使用选择器小工具中的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::*)]")
库(rvest)
url可能与同一问题重复,该值是使用JavaScript生成的。改用硒。@YifuYan谢谢你的链接。我还没有使用硒的经验,因此我还不能找到解决方案。由于我不熟悉JavaScript,我能否向您确认,如果我遇到任何网站的源代码中有JavaScript标记,我不应该使用rvest,而直接使用Rselenium?谢谢您完全可以使用rvest
,但这需要更多的技术。例如,您可以在该网站中使用隐藏的api:http://financials.morningstar.com/finan/financials/getFinancePart.html?&callback=jsonp1529983223636&t=XSES:H78®ion=sgp&culture=en-US&cur=&order=asc&=1529983223703
您可以查看我的其他答案以供参考:
webpage[[1]]
<pointer: 0x07928060>
webpage[[2]]
<pointer: 0x0778adc8>