Vote count: 0
My output data should be similar to the image I've attached
I have used following code but I'm getting an error
Error in bind_rows_(x, .id) : Can not automatically convert from character to integer in column "Runs"
I have used following sample code
require(rvest) require(tidyverse)
urls <- c("http://ift.tt/2kpHLDd", "http://ift.tt/2k6ro24", "http://ift.tt/2kpJzvQ", "http://ift.tt/2k6jQww", "http://ift.tt/2kpvL4y", "http://ift.tt/2k6mthR" )
extra_cols <- list(tibble("Team"="IND","Player"="B.Kumar","won"=1,"lost"=0,"D"=1,"D/N"=0,"innings"=1,"Format"="ODI"), tibble("Team"="IND","Player"="B.Kumar","won"=1,"lost"=0,"D"=0,"D/N"=1,"innings"=2,"Format"="ODI"), tibble("Team"="IND","Player"="B.Kumar","won"=0,"lost"=1,"D"=1,"D/N"=0,"innings"=1,"Format"="ODI"), tibble("Team"="IND","Player"="B.Kumar","won"=0,"lost"=1,"D"=1,"D/N"=0,"innings"=2,"Format"="ODI"), tibble("Team"="IND","Player"="B.Kumar","won"=0,"lost"=1,"D"=0,"D/N"=1,"innings"=1,"Format"="ODI"), tibble("Team"="IND","Player"="B.Kumar","won"=0,"lost"=1,"D"=0,"D/N"=1,"innings"=2,"Format"="ODI") )
doc <- map(urls, read_html) %>% map(html_node, ".engineTable:nth-child(5)")
keep <- map_lgl(doc, ~class(.) != "xml_missing") #### condition to exclude when web urls return "NO Records"###
table<-map(doc[keep], html_table, fill = TRUE) %>% map2_df(extra_cols[keep], cbind)
Web Scraping - Using R, Error in bind_rows_(x, .id)
Aucun commentaire:
Enregistrer un commentaire