0

I am trying to read the reviews related to app present on google play store. I am using Selenium for this purpose. Each review present in jscontroller ="H6e0Ge".

enter image description here

Inside jscontroller = "H6e0Ge" tag, I am trying to retrieve the rating given by the user is associated by the "aria-label", as shown in the picture.

enter image description here

To read rating of all reviewers, my code is

driver = webdriver.Chrome('/Users/yasirmuhammad/Downloads/chromedriver')
driver.get('https://play.google.com/store/apps/details?id=com.axis.drawingdesk.v3&hl=en&showAllReviews=true')
for a in driver.find_elements_by_xpath("//*[@class='d15Mdf bAhLNe']"):
    print(a.find_element_by_class_name('X43Kjb').text)
    print(a.find_element_by_class_name('p2TkOb').text)
    print(a.find_element_by_xpath('/html/body/div[1]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/div/div[2]/div/div[2]/div[1]/div[1]/div/span[1]/div/div').get_attribute('aria-label'))

Third print statement reads the rating, but the problem is it remain same for all users. The reason is because I copied the full xpath of rating of first user, hence it shows the same rating for other users. So I replace the third statement with below statement:

print(a.find_element_by_class_name('pf5lIe').get_attribute('aria-label'))

However, this statement returns "None". Could anyone guide me how should I read the "aria-label" related information?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
user2293224
  • 2,128
  • 5
  • 28
  • 52

3 Answers3

1

You cannot use H6e0Ge and html/body/div[1]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/div/div[2]/div/div[2]/div[1]/div[1]/div/span[1]/div/div like locators, because they dynamically changes and will not work very soon.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

reviews = WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.XPATH, "//h3[.='User reviews']/following-sibling::div[1]/div")))
for review in reviews:
    print(review.find_element_by_xpath(".//span[1]").text)
    print(review.find_element_by_xpath(".//span[2]").text)
    print(review.find_element_by_xpath(".//div[@role='img']").get_attribute('aria-label'))
    print(review.find_element_by_xpath("descendant::div[@jscontroller][last()])").text)

Xpaths:

//h3[.='User reviews']/following-sibling::div[1]/div//span[1]
//h3[.='User reviews']/following-sibling::div[1]/div//span[2]
//h3[.='User reviews']/following-sibling::div[1]//div[@role='img']
//h3[.='User reviews']/following-sibling::div[1]/div/descendant::div[@jscontroller][last()]
Sers
  • 12,047
  • 2
  • 12
  • 31
  • Thanks for the answer. If we want to dig down further I mean If I want to extract the actual comments of the reviewers (which is further down) on the page then shall I use some thing like review.find_element_by_xpath(".//span[3]").text)??? – user2293224 Jan 23 '20 at 10:50
  • review.find_element_by_xpath("descendant::div[@jscontroller][last()])").text – Sers Jan 23 '20 at 11:13
0

You are trying to read the attribute of the parent <div> of the tag, but it is not there. You need to fix your code as follows:

print(a.find_element_by_xpah('.//div[@jscontroller and @jsmodel and @jsdata]//span[@class='nt2C1d']//div[@aria-label]').get_attribute('aria-label'))
Evgeniy Chiruk
  • 358
  • 1
  • 10
0

To read rating of all reviewers you need to induce WebDriverWait for the visibility_of_all_elements_located() and you can use the following Locator Strategies:

  • Using XPATH:

    driver.get('https://play.google.com/store/apps/details?id=com.axis.drawingdesk.v3&hl=en&showAllReviews=true')
    print([my_elem.get_attribute("aria-label") for my_elem in WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.XPATH, "//h3[text()='User reviews']//following::div[1]//span[text()]//following::div[1]//div[@role='img']")))])
    
  • Console Output:

    ['Rated 4 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 1 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 4 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 4 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 4 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars', 'Rated 5 stars out of five stars']
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352