-2

I am using selenium to scrape reviews from tripadvisor.com. I haven't found the right way to extract all the review rating made by users:"ui_bubble_rating bubble_50", 50 = 5 star.

<span class="ui_bubble_rating bubble_50"></span>
::before==$0
::after==$0

Is there any way to extract the number using selenium? Anyone knows, please help to point out with many thanks.

I tried the code below, but the xpath can't find the value I need. It provided only one star rating which is same for all review.

var = driver.find_element_by_xpath("//span[contains(@class, 'ui_bubble_rating bubble_')]").get_attribute("class")

I need the star rating of each review, please have a look at the photo below for what I need. Thank you

Hi. I finally solved my problem. Thank you so much for your time. I just put the answer here in case someone needs.

var = driver.find_element_by_class_name('ui_bubble_rating').get_attribute('class')
review_rating = var.split("_")[-1]
Julie
  • 151
  • 1
  • 1
  • 8

1 Answers1

1
  1. Get class name value and store in 'var'
  2. split class name using underscore and it will return array with splitted string
  3. access value at last index of array 'data' it will contain elements like "ui","bubble","rating bubble","50"

     var = driver.
             find_element_by_xpath("//span[contains(@class, 
                   'ui_bubble_rating bubble_')]").get_attribute("class")
    data = var.split("_")
    print data[-1]
    
Amit Jain
  • 4,389
  • 2
  • 18
  • 21
  • thanks for your answer, but I can't find the value from your xpath. Please check the update. – Julie Aug 28 '18 at 05:06