Last active
August 29, 2015 14:16
-
-
Save smach/1660f6cf3d8a68440024 to your computer and use it in GitHub Desktop.
atlantawx.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url <- "http://forecast.weather.gov/MapClick.php?lat=33.74899931200048&lon=-84.38797796399967&site=all&smap=1#.VPUbWfnF9EI" | |
library(rvest) | |
html <- html(url) | |
forecasthtml <- html_nodes(html, ".row-forecast") | |
forecast <- html_text(forecasthtml) | |
# Note: to deal with the lack of spaces now between Today, Tonight, etc. and the start of the forecasts, I added | |
forecast_formatted <- gsub("day([A-Z])", "day \\1", forecast) | |
forecast_formatted <- gsub("Night([A-Z])", "Night \\1", forecast_formatted) | |
forecast_formatted <- gsub("Tonight([A-Z])", "Tonight \\1", forecast_formatted) | |
forecast_formatted <- gsub("Afternoon([A-Z])", "Afternoon \\1", forecast_formatted) | |
forecast_formatted <- gsub("Day([A-Z])", "Day \\1", forecast_formatted) | |
# This last line just prints it out nicely on the screen. Could also save to variable or file. | |
cat(paste(forecast_formatted, collapse = "\n\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment