I have a series of address records in text, and I need to get LAT and LONG. To avoid using the google maps API, I am trying to perform the search of the addresses in Google to get the full URLs of google maps where LAT and LONG appear. So far I have this code, which only returns the first part of the URL of the search result. Any ideas to get the full link?
#libraries.
install.packages("URLencode")
install.packages("rvest")
library(URLencode)
library(rvest)
#load data
d <- read.csv("/domicilios.csv",sep = ";",col.names = "direccion", stringsAsFactors = FALSE, encoding = "UTF-8")
c <- as.character(d$direccion)
# Function for getting website.
getWebsite <- function(name)
{
url = URLencode(paste0("https://www.google.com/search?q=",name))
page <- read_html(url)
results <- page %>%
html_nodes("cite") %>%
html_text()
result <- results[1]
return(as.character(result)) # Return results if you want to see them all.
}
# Apply the function to a list of company names.
websites <- data.frame(Website = sapply(c,getWebsite))