コード例 #1
0
ファイル: reviews.py プロジェクト: christineli/Lucid
    def __init__(self, api, ItemId=None, URL=None):
        self._asin = None
        if ItemId and not URL:
            # check for http://www.amazon.com
            if 'amazon' in ItemId:
                raise ValueError('URL passed as ASIN')

            URL = reviews_url(ItemId)
        elif not URL and not ItemId:
            raise ValueError('Invalid review page parameters. Input a URL or a valid ASIN!')
        elif URL and 'product-reviews' not in URL:  # If product-reviews is in the url it's probably a valid product review page. Let it be.
            # cleanup the url
            URL = reviews_url(extract_reviews_id(URL))

        self.api = api
        self._URL = URL
        self._soup = None
コード例 #2
0
    def __init__(self, api, ItemId=None, URL=None):
        self._asin = None
        if ItemId and not URL:
            # check for http://www.amazon.com
            if 'amazon' in ItemId:
                raise ValueError('URL passed as ASIN')

            URL = reviews_url(ItemId)
        elif not URL and not ItemId:
            raise ValueError('Invalid review page parameters. Input a URL or a valid ASIN!')
        elif URL and 'product-reviews' not in URL:  # If product-reviews is in the url it's probably a valid product review page. Let it be.
            # cleanup the url
            URL = reviews_url(extract_reviews_id(URL))

        self.api = api
        self._URL = URL
        self._soup = None
コード例 #3
0
    def reviews_url(self):
        # we could use the asin to directly make a review url
        # but some products actually use the ISBN for the review url
        # and the ASIN version would fail
        # so we'll get the url given to us, and get the asin/isbn from that
        try:
            # the variable has changed in python simple product api, sigh
            item = getattr(self.product, 'item', None)
            if not item:
                item = getattr(self.product, 'parsed_response', None)

            url = unicode(item['CustomerReviews']['IFrameURL'])

            p = urlparse.urlparse(url)
            q = urlparse.parse_qs(p.query)
            asin = q['asin'][0]
        except Exception as e:
            asin = self.asin

        reviews = reviews_url(asin)

        return reviews
コード例 #4
0
ファイル: product.py プロジェクト: TJJonesy16/amazon_scraper
    def reviews_url(self):
        # we could use the asin to directly make a review url
        # but some products actually use the ISBN for the review url
        # and the ASIN version would fail
        # so we'll get the url given to us, and get the asin/isbn from that
        try:
            # the variable has changed in python simple product api, sigh
            item = getattr(self.product, 'item', None)
            if not item:
                item = getattr(self.product, 'parsed_response', None)

            url = unicode(item['CustomerReviews']['IFrameURL'])

            p = urlparse.urlparse(url)
            q = urlparse.parse_qs(p.query)
            asin = q['asin'][0]
        except Exception as e:
            asin = self.asin

        reviews = reviews_url(asin)

        return reviews
コード例 #5
0
ファイル: test_product.py プロジェクト: christineli/Lucid
 def test_reviews_url(self):
     p = self.amzn.lookup(ItemId="B00FLIJJSA")
     assert p.reviews_url == amazon_scraper.reviews_url("B00FLIJJSA"), p.reviews_url
コード例 #6
0
 def test_reviews_url(self):
     p = self.amzn.lookup(ItemId='B00FLIJJSA')
     assert p.reviews_url == amazon_scraper.reviews_url('B00FLIJJSA'), p.reviews_url