mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
website changes
This commit is contained in:
parent
2a333aa46a
commit
c07e54d988
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||
store_version = 1 # Needed for dynamic plugin loading
|
||||
store_version = 2 # Needed for dynamic plugin loading
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||
@ -41,30 +41,25 @@ class WHSmithUKStore(BasicStoreConfig, StorePlugin):
|
||||
d.exec_()
|
||||
|
||||
def search(self, query, max_results=10, timeout=60):
|
||||
url = ('http://www.whsmith.co.uk/CatalogAndSearch/SearchWithinCategory.aspx'
|
||||
'?cat=\eb_eBooks&gq=' + urllib2.quote(query))
|
||||
url = ('http://www.whsmith.co.uk/search?keywordCategoryId=wc_dept_ebooks&results=60'
|
||||
'&page=1&keywords=' + urllib2.quote(query))
|
||||
|
||||
br = browser()
|
||||
|
||||
counter = max_results
|
||||
with closing(br.open(url, timeout=timeout)) as f:
|
||||
doc = html.fromstring(f.read())
|
||||
for data in doc.xpath('//div[@class="product-search"]/'
|
||||
'div[contains(@id, "whsSearchResultItem")]'):
|
||||
for data in doc.xpath('//li[@class="product"]'):
|
||||
if counter <= 0:
|
||||
break
|
||||
|
||||
id = ''.join(data.xpath('.//a[contains(@id, "labelProductTitle")]/@href'))
|
||||
if not id:
|
||||
id_ = ''.join(data.xpath('./a[@class="product_image_wrap"]/@href'))
|
||||
if not id_:
|
||||
continue
|
||||
cover_url = ''.join(data.xpath('.//a[contains(@id, "hlinkProductImage")]/img/@src'))
|
||||
title = ''.join(data.xpath('.//a[contains(@id, "labelProductTitle")]/text()'))
|
||||
author = ', '.join(data.xpath('.//div[@class="author"]/h3/span/text()'))
|
||||
price = ''.join(data.xpath('.//span[contains(@id, "labelProductPrice")]/text()'))
|
||||
pdf = data.xpath('boolean(.//span[contains(@id, "labelFormatText") and '
|
||||
'contains(., "PDF")])')
|
||||
epub = data.xpath('boolean(.//span[contains(@id, "labelFormatText") and '
|
||||
'contains(., "ePub")])')
|
||||
id_ = 'http://www.whsmith.co.uk' + id_
|
||||
cover_url = ''.join(data.xpath('.//img[@class="product_image"]/@src'))
|
||||
title = ''.join(data.xpath('.//h4[@class="product_title"]/text()'))
|
||||
author = ', '.join(data.xpath('.//span[@class="product_second"]/text()'))
|
||||
price = ''.join(data.xpath('.//span[@class="price"]/text()'))
|
||||
counter -= 1
|
||||
|
||||
s = SearchResult()
|
||||
@ -73,12 +68,7 @@ class WHSmithUKStore(BasicStoreConfig, StorePlugin):
|
||||
s.author = author.strip()
|
||||
s.price = price
|
||||
s.drm = SearchResult.DRM_LOCKED
|
||||
s.detail_item = id
|
||||
formats = []
|
||||
if epub:
|
||||
formats.append('ePub')
|
||||
if pdf:
|
||||
formats.append('PDF')
|
||||
s.formats = ', '.join(formats)
|
||||
s.detail_item = id_
|
||||
s.formats = 'ePub'
|
||||
|
||||
yield s
|
||||
|
Loading…
x
Reference in New Issue
Block a user