RSelenium: scraping a FULL expandable table

2019-08-21 03:04发布

Based off this question, the OP wants to scrape the table "All Holdings," from this page - scroll down to the yellow part. The table shows the first 10 rows, but can expand to quite a few more.

Both of my rvest and RSelenium solutions only take the first 10 rows, when we want the entire table. My code:

rvest code

library(tidyverse)
library(rvest)

etf_url <- "http://innovatoretfs.com/etf/?ticker=ffty"

etf_table <- etf_url %>%
  read_html %>%
  html_table(fill = T) %>% 
  .[[5]]

RSelenium code

library(RSelenium)
library(rvest)

remDr <- remoteDriver(port = 4445L, remoteServerAddr = "localhost",
                  browserName = "chrome")
remDr$open()
remDr$navigate("http://innovatoretfs.com/etf/?ticker=ffty")
page <- read_html(remDr$getPageSource()[[1]])
table <- html_table(page, fill = TRUE, header = T)
table[[5]]

How can we get the FULL table? Thanks.

1条回答
SAY GOODBYE
2楼-- · 2019-08-21 03:09

Following should expand the table - didn't test it in Selenium but it should work.

remDr$executeScript("__doPostBack('ctl00$BodyPlaceHolder$ViewHoldingsLinkButton','')", args = list())
查看更多
登录 后发表回答