Scraping data from TripAdvisor using R

后端 未结 1 1167
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 02:10

I want to create a crawler that will scrape some data from Trip Advisor. Ideally, it will (a) identify the links to all locations to crawl, (b)

相关标签:
1条回答
  • 2021-02-06 03:05

    Basically, you can try to send a click event to the <div class="morePopularCities">. Something like this :

    remDr$navigate(tu)
    div <- remDr$findElement("class", "morePopularCities")
    div$clickElement()
    

    To expand all locations, you can possibly repeat the above logic in a while loop. Keep clicking on the <div> until no more items available (until the div no longer in the page) :

    divs <- remDr$findElements("class", "morePopularCities")
    while(length(divs )>0) {
      for(div in divs ){
        div$clickElement()
      }
      divs <- remDr$findElements("class", "morePopularCities")
    }
    

    I'm not fluent in R, you may find my code example not pretty, feel free to suggest.

    0 讨论(0)
提交回复
热议问题