diff --git a/src/calibre/gui2/store/stores/amazon_plugin.py b/src/calibre/gui2/store/stores/amazon_plugin.py index 4bd1a42c9d..e26aa2a133 100644 --- a/src/calibre/gui2/store/stores/amazon_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_plugin.py @@ -6,8 +6,6 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import random -import re from contextlib import closing from lxml import html @@ -130,16 +128,16 @@ class AmazonKindleStore(StorePlugin): data_xpath = '//div[contains(@class, "prod")]' format_xpath = './/ul[contains(@class, "rsltL")]//span[contains(@class, "lrg") and not(contains(@class, "bld"))]/text()' - asin_xpath = './/div[@class="image"]/a[1]' + asin_xpath = '@name' cover_xpath = './/img[@class="productImage"]/@src' title_xpath = './/h3[@class="newaps"]/a//text()' author_xpath = './/h3[@class="newaps"]//span[contains(@class, "reg")]/text()' price_xpath = './/ul[contains(@class, "rsltL")]//span[contains(@class, "lrg") and contains(@class, "bld")]/text()' - + for data in doc.xpath(data_xpath): if counter <= 0: break - + # Even though we are searching digital-text only Amazon will still # put in results for non Kindle books (author pages). Se we need # to explicitly check if the item is a Kindle book and ignore it @@ -147,21 +145,15 @@ class AmazonKindleStore(StorePlugin): format = ''.join(data.xpath(format_xpath)) if 'kindle' not in format.lower(): continue - + # We must have an asin otherwise we can't easily reference the # book later. - asin_href = None - asin_a = data.xpath(asin_xpath) - if asin_a: - asin_href = asin_a[0].get('href', '') - m = re.search(r'/dp/(?P.+?)(/|$)', asin_href) - if m: - asin = m.group('asin') - else: - continue + asin = data.xpath(asin_xpath) + if asin: + asin = asin[0] else: continue - + cover_url = ''.join(data.xpath(cover_xpath)) title = ''.join(data.xpath(title_xpath)) @@ -172,9 +164,9 @@ class AmazonKindleStore(StorePlugin): pass price = ''.join(data.xpath(price_xpath)) - + counter -= 1 - + s = SearchResult() s.cover_url = cover_url.strip() s.title = title.strip() diff --git a/src/calibre/gui2/store/stores/amazon_uk_plugin.py b/src/calibre/gui2/store/stores/amazon_uk_plugin.py index 0f9caf8f3e..486671c729 100644 --- a/src/calibre/gui2/store/stores/amazon_uk_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_uk_plugin.py @@ -6,8 +6,6 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import re - from contextlib import closing from lxml import html @@ -53,7 +51,7 @@ class AmazonUKKindleStore(StorePlugin): data_xpath = '//div[contains(@class, "prod")]' format_xpath = './/ul[contains(@class, "rsltL")]//span[contains(@class, "lrg") and not(contains(@class, "bld"))]/text()' - asin_xpath = './/div[@class="image"]/a[1]' + asin_xpath = '@name' cover_xpath = './/img[@class="productImage"]/@src' title_xpath = './/h3[@class="newaps"]/a//text()' author_xpath = './/h3[@class="newaps"]//span[contains(@class, "reg")]/text()' @@ -73,15 +71,9 @@ class AmazonUKKindleStore(StorePlugin): # We must have an asin otherwise we can't easily reference the # book later. - asin_href = None - asin_a = data.xpath(asin_xpath) - if asin_a: - asin_href = asin_a[0].get('href', '') - m = re.search(r'/dp/(?P.+?)(/|$)', asin_href) - if m: - asin = m.group('asin') - else: - continue + asin = data.xpath(asin_xpath) + if asin: + asin = asin[0] else: continue