I am currently using Rvest to try and pull all links from the following url: https://www.zillow.com/browse/homes/fl/miami-dade-county/ The below code satisfies what I am looking to do for one url.
#dl packages
library(tidyverse)
library(rvest)
library(xml2)
library(stringi)
library(dplyr)
library(purrr)
library(stringr)
webpage <- "https://www.zillow.com/browse/homes/fl/miami-dade-county/"
webpage <- read_html(webpage)
url_ <- webpage %>%
html_nodes("a") %>%
html_attr("href")
I am attempting to duplicate this (either a for loop or lapply) for a dataframe (called newurl) full of the same url (zillow.com/browse/homes/fl/ but each ending in a different county). I have tried both looping and lapplying but receive a different error each time. I have included my most recent error and code attempt below. Looking for advice on code to use to satisfy my need or how to edit existing. Thank you.
I have attempted many different codes but my most recent is below.
bind_rows(lapply(newurl, function(x) {
data.frame(newurl=x, toc_entry=toc <- read_html(newurl[1]) %>%
html_nodes("a") %>%
html_attr("href"))
})) -> toc_entries
this produces the following error: Error in UseMethod("read_xml") : no applicable method for 'read_xml' applied to an object of class "data.frame"