【发布时间】:2021-03-17 19:47:39
【问题描述】:
我似乎无法确定与 RSelenium 一起使用以返回任何数据的正确 css 选择器。 网址是:https://www.rbcroyalbank.com/investments/gic-rates.html
所需数据是不可赎回 GIC 利率,每年支付的利息(第二列):1、2、3、4、5、7、10
一些失败的努力
library("RSelenium")
library("rvest")
library("httr")
library("tidyverse")
remDr$navigate("https://www.rbcroyalbank.com/investments/gic-rates.html")
webElem <- remDr$findElement(using = "css selector", value = "tr:nth-child(7) .text-center:nth-child(2) div")
# OR
pg <- remDr$getPageSource()[[1]]
df <- tibble(Rates = pg %>%
read_html() %>%
html_nodes(xpath = '//tr[(((count(preceding-sibling::*) + 1) = 6) and parent::*)]//*[contains(concat( " ", @class, " " ), concat( " ", "text-center", " " )) and (((count(preceding-sibling::*) + 1) = 2) and parent::*)]//div') %>%
html_text())
【问题讨论】:
标签: r web-scraping rselenium