I have been trying to get property listings data from a website where sometimes there is a 'View More' button to load more results and sometimes it is not there. In the first case, I have been using the following code and it works fine. For example,
url<- "http://www.magicbricks.com/property-for-rent/residential-real-estate?bedroom=2&proptype=Multistorey-Apartment,Builder-Floor-Apartment,Penthouse,Studio-Apartment,Service-Apartment,Residential-House,Villa&cityName=Navi-Mumbai&Locality=Vashi"
remDr$navigate(url)
Sys.sleep(3)
webElem <- remDr$findElement("css", "#viewMoreButton a")
while(webElem$isElementDisplayed()[[1]]){
tryCatch({
Sys.sleep(1)
webElem <- remDr$findElement("css", "#viewMoreButton a")
webElem$clickElement()
}, error=function(e){})
}
mb<- read_html(remDr$getPageSource()[[1]])
But in the second case, it doesn't work. For example:
url<- "http://www.magicbricks.com/property-for-rent/residential-real-estate?bedroom=4&proptype=Multistorey-Apartment,Builder-Floor-Apartment,Penthouse,Studio-Apartment,Service-Apartment,Residential-House,Villa&cityName=Navi-Mumbai&Locality=Vashi"
remDr$navigate(url)
Sys.sleep(3)
webElem <- remDr$findElement("css", "#viewMoreButton a")
while(webElem$isElementDisplayed()[[1]]){
tryCatch({
Sys.sleep(1)
webElem <- remDr$findElement("css", "#viewMoreButton a")
webElem$clickElement()
}, error=function(e){})
}
mb<- read_html(remDr$getPageSource()[[1]])
This code gets stuck at the line 'WebElem<- renDr$findElement()' and doesn't move forward or throw error.
What am I doing wrong?