RSelenium: scraping a FULL expandable table

主宰稳场 提交于 2019-12-13 03:58:01

问题


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:


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

remDr$executeScript("__doPostBack('ctl00$BodyPlaceHolder$ViewHoldingsLinkButton','')", args = list())


来源:https://stackoverflow.com/questions/51353272/rselenium-scraping-a-full-expandable-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!