Escrapeamos APIs de Bloomber para ver cambio de monedas de Dólares a Soles
pacman::p_load(
rvest,httr,jsonlite,tidyverse,lubridate,plotly
)
read_url <- function(url){
GET(url,
config = add_headers(.headers = c(
"User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
))
) %>% content()
}
(read_url(api_semanal) %>%
map_df("price") %>%
transmute(`DOL a PEN`=value,Fechas = ymd(dateTime)) %>%
ggplot(aes(Fechas,`DOL a PEN`)) +
geom_line(size=0.6,alpha=0.7))
(read_url(api_diario) %>%
map_df("price") %>%
transmute(`DOL a PEN`=value,Fechas = ymd(dateTime)) %>%
ggplot(aes(Fechas,`DOL a PEN`)) +
geom_line(size=0.6,alpha=0.7))
If you see mistakes or want to suggest changes, please create an issue on the source repository.
For attribution, please cite this work as
Caballero (2022, March 5). Keith Stats Blog: Web Scraping API USD a PEN - Bloomberg. Retrieved from https://keithstatsblog.netlify.app/posts/2022-03-05-web-scraping-pen-bloomberg/
BibTeX citation
@misc{caballero2022web, author = {Caballero, Keith}, title = {Keith Stats Blog: Web Scraping API USD a PEN - Bloomberg}, url = {https://keithstatsblog.netlify.app/posts/2022-03-05-web-scraping-pen-bloomberg/}, year = {2022} }