R Markdown

Change link below to the any earch criteria from turbo.az website

library(rvest, warn.conflicts=F, quietly=T)
library(dplyr, warn.conflicts=F, quietly=T)
library(tidyr, warn.conflicts=F, quietly=T)
library(stringr, warn.conflicts=F, quietly=T)

link="https://turbo.az/autos?page="

get_moreInfo_func=function(car_link){
  moreInfo_page=read_html(car_link)
  moreInfo=moreInfo_page %>% html_nodes(".seller-phone")%>%html_text() %>% paste(collapse ="," )
  return(moreInfo)
}

car_data=data.frame()   #Create empty data frame

for (i in seq(1:2)){
  link=paste(link,i,sep="")
  page=read_html(link)
  
  car_name=page %>% html_nodes("div.products-i__name.products-i__bottom-text") %>% html_text()
  car_links=page %>% html_nodes("a.products-i__link") %>% html_attr("href") %>% paste("https://turbo.az",.,sep="")
  car_info=page %>% html_nodes("div.products-i__attributes.products-i__bottom-text") %>%html_text()
  car_price=page%>%html_nodes("div.product-price")%>%html_text()
  ad_time=page %>% html_nodes("div.products-i__datetime") %>% html_text()
  
  car_moreInfo=sapply(car_links, FUN=get_moreInfo_func, USE.NAMES = FALSE)
  
  car_data=rbind(car_data, data.frame(car_name, car_info,car_price, ad_time, car_moreInfo, car_links, stringsAsFactors = FALSE))
  
  print(paste("Page ",i," scrapped!"))  
}
## [1] "Page  1  scrapped!"
## [1] "Page  2  scrapped!"

##Now lets inspect the result

Note that, announcements from the car sale shops are not going appear in this list. Their html tags are different

head(car_data)
##                 car_name                car_info  car_price
## 1                 Kia K5       2022, 2.0 L, 0 km 51 900 AZN
## 2          Nissan Xterra       2022, 2.5 L, 0 km   48 800 $
## 3 Land Rover Range Rover  2015, 5.0 L, 95 800 km   79 000 $
## 4                  MG GT       2022, 1.5 L, 0 km 39 600 AZN
## 5  Mercedes Sprinter 313  2005, 2.2 L, 55 000 km   55 000 $
## 6         Hyundai Accent 2011, 1.6 L, 140 000 km 17 300 AZN
##                  ad_time    car_moreInfo
## 1 Bakı, 04.11.2022 09:16                
## 2 Bakı, 03.11.2022 16:18                
## 3 Bakı, 02.11.2022 13:13                
## 4 Bakı, 30.10.2022 21:58                
## 5 Bakı, 18.10.2022 16:57 (050) 213-66-86
## 6 Bakı, 04.11.2022 14:36 (070) 511-65-55
##                                               car_links
## 1                 https://turbo.az/autos/6714292-kia-k5
## 2          https://turbo.az/autos/6103936-nissan-xterra
## 3 https://turbo.az/autos/6747079-land-rover-range-rover
## 4                  https://turbo.az/autos/6621155-mg-gt
## 5  https://turbo.az/autos/5425981-mercedes-sprinter-313
## 6         https://turbo.az/autos/6766988-hyundai-accent