Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions yandex_reviews_parser/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def get_count_star(review_stars: list) -> Union[float, int]:
:param review_stars: Массив элементов звезд рейтинга
:return: Рейтинг
"""
star_count: float = 0
star_count: int = 0
for review_star in review_stars:
if '_empty' in review_star.get_attribute('class'):
continue
if '_half' in review_star.get_attribute('class'):
star_count = star_count + 0.5
if '_full' in review_star.get_attribute('class'):
star_count += 1
continue
star_count = star_count + 1

return star_count
7 changes: 3 additions & 4 deletions yandex_reviews_parser/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@ def __get_data_item(self, elem):
icon_href = icon_href.split('"')[1]
except NoSuchElementException:
icon_href = None

try:
date = elem.find_element(By.XPATH, ".//meta[@itemprop='datePublished']").get_attribute('content')
except NoSuchElementException:
date = None

try:
text = elem.find_element(By.XPATH, ".//span[@class='business-review-view__body-text']").text
text = elem.find_element(By.CLASS_NAME, "business-review-view__body").text
except NoSuchElementException:
text = None
try:
stars = elem.find_elements(By.XPATH, ".//div[@class='business-rating-badge-view__stars _spacing_normal']/span")
stars = elem.find_elements(By.CSS_SELECTOR, ".business-review-view__rating span")
stars = ParserHelper.get_count_star(stars)
except NoSuchElementException:
stars = 0
Expand Down Expand Up @@ -112,7 +111,7 @@ def __get_data_campaign(self) -> dict:
xpath_count_rating = ".//div[@class='business-summary-rating-badge-view__rating-count']/span[@class='business-rating-amount-view _summary']"
count_rating_list = rating_block.find_element(By.XPATH, xpath_count_rating).text
count_rating = ParserHelper.list_to_num(count_rating_list)
xpath_stars = ".//div[@class='business-rating-badge-view__stars _spacing_normal']/span"
xpath_stars = ".//div[@class='business-rating-badge-view__stars']/span"
stars = ParserHelper.get_count_star(rating_block.find_elements(By.XPATH, xpath_stars))
except NoSuchElementException:
rating = 0
Expand Down