Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Last active April 19, 2022 07:24
Show Gist options
  • Save prashantvc/ba99a7fa621ec92a9041fea45361c962 to your computer and use it in GitHub Desktop.
Save prashantvc/ba99a7fa621ec92a9041fea45361c962 to your computer and use it in GitHub Desktop.
## install libraries
library(rvest)
library(dplyr)
get_details <- function(page_link) {
page_details <- read_html(page_link)
address <- page_details |>
html_nodes(".lng_add") |>
last() |>
html_text()
# check if address is null
if (length(address) == 0) {
return("NA")
}
return(address)
}
store_table <- data.frame()
for (page_result in seq(from = 1, to = 5, by = 1)) {
link <- paste0(
"https://www.justdial.com/Bangalore/Plant-Nurseries/page-",
page_result
)
page <- read_html(link)
stores <- page |> html_nodes(".store-details")
store_link <- stores |>
html_nodes(".store-name a") |>
html_attr("href")
names <- stores |>
html_nodes(".lng_cont_name") |>
html_attr("data-cn")
store_add <- sapply(store_link, FUN = get_details)
store_table <- rbind(
store_table,
data.frame(
name = names,
address = store_add
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment