Я думаю, что-то вроде этого должно сработать, чтобы получить информацию, которую вы ищете.
library(rvest)
zip.codes <- c("33415", "33413")
results <- list()
result.index <- 0
for(zip in zip.codes){
url <- paste0("https://www.realtor.com/realestateagents/", zip ,"/pg-1" )
page <- read_html(url)
max.pages <- as.numeric(max(page %>%
html_nodes(xpath = '//*[@class="page"]') %>%
html_nodes("a") %>%
html_text))
for(i in c(1:max.pages)){
print(paste("Processing Zip Code", zip, "- Page", i, "of", max.pages))
result.index <- result.index + 1
url <- paste0("https://www.realtor.com/realestateagents/", zip,"/pg-", i)
page <- read_html(url)
df <- data.frame(AgentID = page %>%
html_nodes(xpath = '//*[@id="call_inquiry_cta"]') %>%
xml_attr("data-agent-id"),
AgentName = page %>%
html_nodes(xpath = '//*[@id="call_inquiry_cta"]') %>%
xml_attr("data-agent-name"),
AgentAddr = page %>%
html_nodes(xpath = '//*[@id="call_inquiry_cta"]') %>%
xml_attr("data-agent-address"),
AgentPhone = sub("tel:", "", page %>%
html_nodes(xpath = '//*[@id="call_inquiry_cta"]') %>%
xml_attr("href")),
PhoneType = page %>%
html_nodes(xpath = '//*[@id="call_inquiry_cta"]') %>%
xml_attr("data-agent-num-type"),
AgentWebSite = page %>%
html_nodes(xpath = '//*[@id="call_inquiry_cta"]') %>%
xml_attr("data-agent-web-url"))
results[[result.index]] <- df
}
}
df <- do.call(rbind, results)