RSelenium:抓取一个完整的可扩展 table
RSelenium: scraping a FULL expandable table
基于 this question, the OP wants to scrape the table "All Holdings," from this page - 向下滚动到黄色部分。 table 显示前 10 行,但可以扩展到更多行。
当我们需要整个 table 时,我的 rvest
和 RSelenium
解决方案都只取前 10 行。我的代码:
rvest代码
library(tidyverse)
library(rvest)
etf_url <- "http://innovatoretfs.com/etf/?ticker=ffty"
etf_table <- etf_url %>%
read_html %>%
html_table(fill = T) %>%
.[[5]]
RSelenium 代码
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]]
我们怎样才能得到完整的table?谢谢。
以下应该扩展 table - 没有在 Selenium 中测试它,但它应该可以工作。
remDr$executeScript("__doPostBack('ctl00$BodyPlaceHolder$ViewHoldingsLinkButton','')", args = list())
基于 this question, the OP wants to scrape the table "All Holdings," from this page - 向下滚动到黄色部分。 table 显示前 10 行,但可以扩展到更多行。
当我们需要整个 table 时,我的 rvest
和 RSelenium
解决方案都只取前 10 行。我的代码:
rvest代码
library(tidyverse)
library(rvest)
etf_url <- "http://innovatoretfs.com/etf/?ticker=ffty"
etf_table <- etf_url %>%
read_html %>%
html_table(fill = T) %>%
.[[5]]
RSelenium 代码
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]]
我们怎样才能得到完整的table?谢谢。
以下应该扩展 table - 没有在 Selenium 中测试它,但它应该可以工作。
remDr$executeScript("__doPostBack('ctl00$BodyPlaceHolder$ViewHoldingsLinkButton','')", args = list())