问题
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