Пример #1
0
    def _parse_restaurant(self, restaurant_soup):
        restaurant = Restaurant()

        # name and url
        title_soup = restaurant_soup.find('a', class_='property_title')
        if title_soup is not None:
            restaurant.name = title_soup.text.strip()
            restaurant.url = self.base_url + title_soup['href'].strip()

        # price
        price_soup = restaurant_soup.find('span', class_='price_range')
        if price_soup is not None:
            restaurant.price = price_soup.text.strip()

        # reviews
        reviews_soup = restaurant_soup.find('span', class_='reviewCount')
        restaurant.review_count = 0
        if reviews_soup is not None:
            reviews_match = re.findall('^\d+\.?\d+', reviews_soup.a.text.strip())
            if reviews_match and len(reviews_match) > 0:
                restaurant.review_count = reviews_match[0].replace('.', '')

        # rating
        rating_soup = restaurant_soup.find('img', class_='sprite-ratings')
        if rating_soup is not None:
            rating = rating_soup['alt'].strip()
            restaurant.rating = self._parse_rating(rating)
            restaurant.max_rating = self._parse_max_rating(rating)

        # ranking
        ranking_soup = restaurant_soup.find('div', class_='popIndexDefault')
        if ranking_soup is not None:
            ranking = ranking_soup.text.strip().replace('.', '')
            restaurant.ranking = self._parse_ranking(ranking)
            restaurant.ranking_len = self._parse_ranking_len(ranking)

        # cuisines
        cuisine_soup_list = restaurant_soup.find_all('a', class_='cuisine')
        if cuisine_soup_list is not None:
            restaurant.cuisines = []
            for tag in cuisine_soup_list:
                restaurant.cuisines.append(tag.text.strip())
        return restaurant