I'm having an issue trying to get Rankings from the Freeride World Tour website.
I tried first to get a CSS code for rvest using selectorGadget
in Chrome but but can only get the riders and their overall score. What I'm interested in is getting the points a rider scored in each heat. I'm new to web-scraping and CSS/HTML so please hang in there with me.
# Get the website url
url <- read_html("https://www.freerideworldtour.com/rankings-detailed?season=165&competition=2&discipline=38")
Download everything from the page,
(all_text <- url %>%
html_nodes("div") %>%
html_text())
then look for Kristofer Turdell's first score of 2500 pts. grep("2500 pts.", all_text)
but I find...nothing?
When I right-click the 2500 pts. on the website and select "Inspect" I can see that the html code for this section is:
<div class="field__item even">2500 pts.</div>
So I tried to use the div class
:
url %>%
html_nodes(".field__item.even:) %>%
html_text()
This only returns the overall score for the participants (e.g. Kristofer Turdell 7870 pts.).
Next, I tried using the right-click option to save Xpath from "Inspect".
url %>%
html_nodes(xpath = "//*[@id="page-content"]/div/div/div[2]/div/div/div/div[1]/div[2]/div/div/div[1]/div/div[4]/div/div/div") %>%
html_text()
I'm not having any luck on this so I'd really appreciate your help.
url <- read_html("https://www.freerideworldtour.com/rider/kristofer-turdell")
and thenurl %>% html_node("div") %>% html_text() %>% gsub("\\s*\\n+\\s*",";",.) %>% gsub("pts.", "\n", .) %>% read.table(text = ., fill = T, sep = ";", row.names = NULL, col.names = c("Drop", "Ranking", "FWT", "Events", "Points")) %>% subset(select=2:5) %>% dplyr::filter(!is.na(as.numeric(as.character(Ranking))))
, following @Onyambu's style. – Kimriders <- c("kristofer-turdell", "markus-eder", "mickael-bimboes")
and a prefix for urlurl_base <- "https://www.freerideworldtour.com/rider/"
I should be able to make a for loop withbind_rows()
however, I can only print to consolefor (i in riders) { read_html(paste0(url_base, i)) %>% html_node("div") %>% ... mutate(name = i) %>% print() }
. Were...
stands for the parts of your code i omitted. – Matthew J. Oldach