1

Rcode:

library(purrr)
library(rvest)
 url_base <-"https://www.franchisedirect.com/top100globalfranchises/rankings?page=%d"
  map_df(1:5,function(i){
    page <- read_html(sprintf(url_base,i))
    data.frame(Rank = html_text(html_nodes(page,".top500listingTableIndustry , .top500listingTableCountry , .top500listingTableName , .tablesaw-cell-content , .top500listingTableRank"))
    )
    }) -> F100
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
FaRz1 Ezpz
  • 15
  • 3
  • 1
    Welcome to SO! Please [re-format your question](https://stackoverflow.com/editing-help) so that the code is more readable. Also, please write a short/concise/relevant subject, then put most of your text in the body (as text), and code (as `code`, preferably with some consistent indenting). Lastly, what is wrong with it? What does it actually give you? Some references for asking questions well: https://stackoverflow.com/help/how-to-ask, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. Please read at least one. – r2evans Apr 07 '18 at 00:40
  • How is the inability to identify the proper CSS an SO R tag question? – hrbrmstr Apr 07 '18 at 01:09
  • please see if my answer helps your question – Winicius Sabino Apr 07 '18 at 01:30

1 Answers1

0

try this

library(rvest)
library(dplyr)
table <- list()
for(i in 1:5){
  url = paste0("https://www.franchisedirect.com/top100globalfranchises/rankings? page=",i)
  webpage = read_html(url)
  table[[i]] <- as.data.frame(html_table(html_nodes(webpage, "table"))) 
  cat("page ",i, " complete", "\n")
}
table2 <- bind_rows(table)

for(i in 1:dim(table2)[2]){
   table2[,i] <- gsub("\\\n", "", table2[,i])
}

write.csv(table2, "table.csv")
Winicius Sabino
  • 1,486
  • 8
  • 17
  • Actually I need a R code by which can scrap the tables from following website https://www.franchisedirect.com/top100globalfranchises/ and after scraping table I am not to get all the values in csv format – FaRz1 Ezpz Apr 07 '18 at 13:15
  • Thanks bro ... its almost the way I want just getting redundant column names with each cell value if u can check ur csv file... but u solved my issue .. much needed help :) tysm – FaRz1 Ezpz Apr 07 '18 at 17:51