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
试试这个
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")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句