mercredi 24 juillet 2019

Scraping the table from multi pages in the website in R

I'm newbie in web scraping and below is my code and I wanted to scrap the table from all the pages (or just first 5 pages should be enough).

Website = https://finviz.com/screener.ashx?v=152&f=cap_midover&o=ticker&r=0

not sure what can I do next in order to get all these 3 pages table in one #table. Please help me, thanks a lot :)

I had tried to run this code but yet there is no table come out from this code

require(dplyr)
require(rvest)

options(stringsAsFactors = FALSE)

url_base <- "https://finviz.com/screener.ashx?v=152&f=cap_midover&o=ticker&r="

tbl.clactions <- data.frame(
  "Ticker" = character(0),"Company" = character(0),
  "Sector" = character(0),"Industry" = character(0),
  "Country" = character(0),"Market.Cap" = character(0),
  "P/E" = character(0),"ROA" = character(0),
  "ROE" = character(0),"Price" = character(0),
  "Change" = character(0),"Volume" = character(0)
)

page <- c(0,21,41)

for (i in page) { 
  url <- paste0(url_base, i)
  tbl.page <- url %>%
    read_html() %>%
    html_nodes(xpath='//*[@id="screener-content"]/table/tbody/tr[4]/td/table') %>%
    html_table()
}

Seems like there is no error for this code




Aucun commentaire:

Enregistrer un commentaire