【发布时间】:2019-08-01 03:42:57
【问题描述】:
我正在尝试从 yahoo Finance 中抓取一些数据。通常我这样做没有问题。然而,今天,我在尝试拉某个容器时遇到了问题。这可能是什么原因让我如此困难?
我尝试了许多 xpath 的组合。选择器小工具由于某种原因无法拾取 xpath。我已经发布了一些尝试和下面的网址。
绿色aea 是我想要带入控制台的东西。
library(tidyverse)
library(rvest)
library(httr)
read_html("https://ca.finance.yahoo.com/quote/SPY/holdings?p=SPY") %>% html_nodes(xpath = '//*[@id="Col1-0-Holdings-Proxy"]/section/div[1]/div[1]')
{xml_nodeset (0)}
#When I search for all tables using the following function.
read_html("https://finance.yahoo.com/quote/xlk/holdings?p=xlk") %>% html_nodes("table") %>% .[1] %>% html_table(fill = T)
我得到了页面底部的表格。在 [] 中尝试不同的数字会导致错误。
我做错了什么?这似乎很容易刮。非常感谢您的帮助。
【问题讨论】:
-
你也需要这两个标题吗?或者只是行(不包括图表)?
-
只是行(部门名称和相关值。即基本材料 - 2.48%)
标签: r xpath web-scraping rvest