mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Store: Fix Wizards Press store when it returns an exact match by loading the detail page.
This commit is contained in:
parent
a3aa8047c9
commit
c69f442060
@ -44,40 +44,70 @@ class WizardsTowerBooksStore(BasicStoreConfig, StorePlugin):
|
|||||||
counter = max_results
|
counter = max_results
|
||||||
with closing(br.open(url, timeout=timeout)) as f:
|
with closing(br.open(url, timeout=timeout)) as f:
|
||||||
doc = html.fromstring(f.read())
|
doc = html.fromstring(f.read())
|
||||||
for data in doc.xpath('//table[@class="gridp"]//td'):
|
if 'search.html' in f.geturl():
|
||||||
if counter <= 0:
|
for data in doc.xpath('//table[@class="gridp"]//td'):
|
||||||
break
|
if counter <= 0:
|
||||||
|
break
|
||||||
|
|
||||||
id = ''.join(data.xpath('.//span[@class="prti"]/a/@href'))
|
id = ''.join(data.xpath('.//span[@class="prti"]/a/@href'))
|
||||||
id = id.strip()
|
id = id.strip()
|
||||||
if not id:
|
if not id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
cover_url = ''.join(data.xpath('.//div[@class="prim"]/a/img/@src'))
|
cover_url = ''.join(data.xpath('.//div[@class="prim"]/a/img/@src'))
|
||||||
cover_url = url_slash_cleaner(self.url + cover_url.strip())
|
cover_url = url_slash_cleaner(self.url + cover_url.strip())
|
||||||
|
|
||||||
price = ''.join(data.xpath('.//font[@class="selling_price"]//text()'))
|
price = ''.join(data.xpath('.//font[@class="selling_price"]//text()'))
|
||||||
price = price.strip()
|
price = price.strip()
|
||||||
if not price:
|
if not price:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
title = ''.join(data.xpath('.//span[@class="prti"]/a/b/text()'))
|
title = ''.join(data.xpath('.//span[@class="prti"]/a/b/text()'))
|
||||||
author = ''.join(data.xpath('.//p[@class="last"]/text()'))
|
author = ''.join(data.xpath('.//p[@class="last"]/text()'))
|
||||||
a, b, author = author.partition(' by ')
|
a, b, author = author.partition(' by ')
|
||||||
|
|
||||||
counter -= 1
|
counter -= 1
|
||||||
|
|
||||||
|
s = SearchResult()
|
||||||
|
s.cover_url = cover_url
|
||||||
|
s.title = title.strip()
|
||||||
|
s.author = author.strip()
|
||||||
|
s.price = price.strip()
|
||||||
|
s.detail_item = id.strip()
|
||||||
|
s.drm = SearchResult.DRM_UNLOCKED
|
||||||
|
|
||||||
|
yield s
|
||||||
|
# Exact match brought us to the books detail page.
|
||||||
|
else:
|
||||||
s = SearchResult()
|
s = SearchResult()
|
||||||
s.cover_url = cover_url
|
|
||||||
s.title = title.strip()
|
cover_url = ''.join(doc.xpath('//div[@id="image"]/a/img[@title="Zoom"]/@src')).strip()
|
||||||
s.author = author.strip()
|
s.cover_url = url_slash_cleaner(self.url + cover_url.strip())
|
||||||
s.price = price.strip()
|
|
||||||
s.detail_item = id.strip()
|
s.title = ''.join(doc.xpath('//form[@name="details"]/h1/text()')).strip()
|
||||||
|
|
||||||
|
authors = doc.xpath('//p[contains(., "Author:")]//text()')
|
||||||
|
author_index = None
|
||||||
|
for i, a in enumerate(authors):
|
||||||
|
if 'author' in a.lower():
|
||||||
|
author_index = i + 1
|
||||||
|
break
|
||||||
|
if author_index is not None and len(authors) > author_index:
|
||||||
|
a = authors[author_index]
|
||||||
|
a = a.replace(u'\xa0', '')
|
||||||
|
s.author = a.strip()
|
||||||
|
|
||||||
|
s.price = ''.join(doc.xpath('//span[@id="price_selling"]//text()')).strip()
|
||||||
|
s.detail_item = f.geturl().replace(self.url, '').strip()
|
||||||
|
s.formats = ', '.join(doc.xpath('//select[@id="N1_"]//option//text()'))
|
||||||
s.drm = SearchResult.DRM_UNLOCKED
|
s.drm = SearchResult.DRM_UNLOCKED
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
|
||||||
def get_details(self, search_result, timeout):
|
def get_details(self, search_result, timeout):
|
||||||
|
if search_result.formats:
|
||||||
|
return False
|
||||||
|
|
||||||
br = browser()
|
br = browser()
|
||||||
with closing(br.open(url_slash_cleaner(self.url + search_result.detail_item), timeout=timeout)) as nf:
|
with closing(br.open(url_slash_cleaner(self.url + search_result.detail_item), timeout=timeout)) as nf:
|
||||||
idata = html.fromstring(nf.read())
|
idata = html.fromstring(nf.read())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user