I've been spending a lot of time trying to figure out the issue here but unfortunately had no luck yet. I hope someone can point me in the right direction.
I'm trying to extract the address elements for all properties listed in the link provided in the script below. However, the output is always an empty list. I've tried different variations but none worked.
lapply(c('XML','httr'),require,character.only=TRUE)
link <- "http://www.realtor.ca/Map.aspx?CultureId=1&ApplicationId=1&RecordsPerPage=9&MaximumResults=9&PropertyTypeId=300&TransactionTypeId=2&SortOrder=A&SortBy=1&LongitudeMin=-114.52066040039104&LongitudeMax=-113.60536193847697&LatitudeMin=50.94776904194829&LatitudeMax=51.14246522072541&PriceMin=0&PriceMax=0&BedRange=0-0&BathRange=0-0&ParkingSpaceRange=0-0&viewState=m&Longitude=-114.063011169434&Latitude=51.0452194213867&ZoomLevel=11&CurrentPage=1#CultureId=1&ApplicationId=1&RecordsPerPage=9&MaximumResults=9&PropertyTypeId=300&TransactionTypeId=2&SortOrder=A&SortBy=1&LongitudeMin=-114.9913558959965&LongitudeMax=-113.1346664428715&LatitudeMin=50.91552869934793&LatitudeMax=51.1745480567661&PriceMin=0&PriceMax=0&BedRange=0-0&BathRange=0-0&ParkingSpaceRange=0-0&viewState=l&Longitude=-114.063011169434&Latitude=51.0452194213867&ZoomLevel=11&CurrentPage=1"
doc <- htmlTreeParse(link,useInternalNodes = T)
addresses <- xpathSApply(doc,"//div[@id='listView']//span",xmlValue)
the output of addresses
is as follows:
> addresses
list()
In fact, I was not able to fetch any of the other html elements in the link above. I wonder if it's because the page takes a while to load whereas GET{httr}
or htmlTreeParse{XML}
instantaneously scrape the webpage without giving it a chance to fully load first. Not sure if my reasoning makes sense. I would appreciate community's assistance with this issue.