Skip to content

Instantly share code, notes, and snippets.

@khunreus
Last active March 24, 2019 19:30
Show Gist options
  • Save khunreus/92ed8a84dfa70ba42982ef5588395c12 to your computer and use it in GitHub Desktop.
Save khunreus/92ed8a84dfa70ba42982ef5588395c12 to your computer and use it in GitHub Desktop.
#reviews_dict = {}
reviews_list = []
sleep(2)
try:
sleep(4)
reviews_button = self.driver.find_element_by_xpath('//*[@class="_ff6jfq"]')
reviews_button.click()
k = 0
profile_scrapy_selector_1 = Selector(text = self.driver.page_source)
# reviewers = profile_scrapy_selector_1.xpath('//*[@id = "reviews"]//section/div[2]//*[@class="_hgs47m"]/div[2]/div[1]/div/div/text()').extract()
# review_dates = profile_scrapy_selector_1.xpath('//*[@id = "reviews"]//section/div[2]//*[@class="_hgs47m"]/div[2]/div[1]/div/span/text()').extract()
reviews = profile_scrapy_selector_1.xpath('//*[@id = "reviews"]//section/div[2]//*[@style="margin-top: 16px;"]/div//*[@dir="ltr"]/text()').extract()
reviews_list.append(reviews)
# for k in range(len(reviewers)):
# reviewer_date = reviewers[k] + ' >> ' + review_dates[k]
# review = reviews[k]
# reviews_dict[reviewer_date] = review
# k = k+1
while True:
# j = 0
sleep(2.15)
try:
next_button = self.driver.find_element_by_xpath('//*[@class="_1rltvky"]//*[@aria-label="Next"]')
sleep(1)
next_button.click()
sleep(2.1)
reviews_scrapy_selector = Selector(text = self.driver.page_source)
# reviewers = reviews_scrapy_selector.xpath('//*[@id = "reviews"]//section/div[2]//*[@class="_hgs47m"]/div[2]/div[1]/div/div/text()').extract()
# review_dates = reviews_scrapy_selector.xpath('//*[@id = "reviews"]//section/div[2]//*[@class="_hgs47m"]/div[2]/div[1]/div/span/text()').extract()
reviews_1 = reviews_scrapy_selector.xpath('//*[@id = "reviews"]//section/div[2]//*[@style="margin-top: 16px;"]/div//*[@dir="ltr"]/text()').extract()
reviews_list.append(reviews_1)
except:
self.logger.info('Failed to navigate the Next page in Reviews.')
except NoSuchElementException:
self.logger.info('No Reviews section to navigate to.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment