使用R Studio从investing.com上抓取STOXX EUROPE 600索引的组件名称



我正在尝试从网站上自动读取STOXX 600 EUROPE组件的名称:https://nl.investing.com/indices/stoxx-600-components.请参阅以下代码:

Library(rvest)
Library(tidyverse)
URL <-  "https://nl.investing.com/indices/stoxx-600-components"
publications <-read_html(URL) %>%
#defined the Node
html_nodes("leftColumn") %>% 
html_text() %>% data.frame()

但有些地方出了问题,因为我看到一个数据集有0个观测值。有人能帮我如何用R工作室从STOXX EUROPE 600指数中提取名字吗。

利用html_table和表的id(cr1(,您可以获得一个包含名称和价格信息的数据帧,如:

library(rvest)
library(tidyverse)
url <-  "https://nl.investing.com/indices/stoxx-600-components"
html <-read_html(url) 
html %>%
html_node("#cr1") %>% 
html_table() %>% 
head()
#> # A tibble: 6 x 10
#>   ``    Naam     Laatst   Hoog     Laag     `+/-`  `+/- %` Vol.    Tijd    ``   
#>   <lgl> <chr>    <chr>    <chr>    <chr>    <chr>  <chr>   <chr>   <chr>   <lgl>
#> 1 NA    3I Group 1.244,00 1.258,00 1.234,50 -11,50 -0,92%  774,92K 17:35:… NA   
#> 2 NA    A2A      1,706    1,722    1,694    -0,007 -0,41%  12,37M  17:35:… NA   
#> 3 NA    AAK      192,8    193,2    191,1    +0,5   +0,23%  246,89K 17:29:… NA   
#> 4 NA    Aalberts 46,93    47,15    46,46    -0,23  -0,49%  66,32K  17:36:… NA   
#> 5 NA    ABB      31,34    31,38    30,98    +0,04  +0,13%  2,71M   17:31:… NA   
#> 6 NA    ABN AMRO 11,29    11,37    11,18    +0,06  +0,52%  2,43M   17:35:… NA

最新更新