website changes

This commit is contained in:
Charles Haley 2014-03-30 10:36:35 +02:00
parent 2a333aa46a
commit c07e54d988

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (unicode_literals, division, absolute_import, print_function) 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' __license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>' __copyright__ = '2011, John Schember <john@nachtimwald.com>'
@ -41,30 +41,25 @@ class WHSmithUKStore(BasicStoreConfig, StorePlugin):
d.exec_() d.exec_()
def search(self, query, max_results=10, timeout=60): def search(self, query, max_results=10, timeout=60):
url = ('http://www.whsmith.co.uk/CatalogAndSearch/SearchWithinCategory.aspx' url = ('http://www.whsmith.co.uk/search?keywordCategoryId=wc_dept_ebooks&results=60'
'?cat=\eb_eBooks&gq=' + urllib2.quote(query)) '&page=1&keywords=' + urllib2.quote(query))
br = browser() br = browser()
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('//div[@class="product-search"]/' for data in doc.xpath('//li[@class="product"]'):
'div[contains(@id, "whsSearchResultItem")]'):
if counter <= 0: if counter <= 0:
break break
id_ = ''.join(data.xpath('./a[@class="product_image_wrap"]/@href'))
id = ''.join(data.xpath('.//a[contains(@id, "labelProductTitle")]/@href')) if not id_:
if not id:
continue continue
cover_url = ''.join(data.xpath('.//a[contains(@id, "hlinkProductImage")]/img/@src')) id_ = 'http://www.whsmith.co.uk' + id_
title = ''.join(data.xpath('.//a[contains(@id, "labelProductTitle")]/text()')) cover_url = ''.join(data.xpath('.//img[@class="product_image"]/@src'))
author = ', '.join(data.xpath('.//div[@class="author"]/h3/span/text()')) title = ''.join(data.xpath('.//h4[@class="product_title"]/text()'))
price = ''.join(data.xpath('.//span[contains(@id, "labelProductPrice")]/text()')) author = ', '.join(data.xpath('.//span[@class="product_second"]/text()'))
pdf = data.xpath('boolean(.//span[contains(@id, "labelFormatText") and ' price = ''.join(data.xpath('.//span[@class="price"]/text()'))
'contains(., "PDF")])')
epub = data.xpath('boolean(.//span[contains(@id, "labelFormatText") and '
'contains(., "ePub")])')
counter -= 1 counter -= 1
s = SearchResult() s = SearchResult()
@ -73,12 +68,7 @@ class WHSmithUKStore(BasicStoreConfig, StorePlugin):
s.author = author.strip() s.author = author.strip()
s.price = price s.price = price
s.drm = SearchResult.DRM_LOCKED s.drm = SearchResult.DRM_LOCKED
s.detail_item = id s.detail_item = id_
formats = [] s.formats = 'ePub'
if epub:
formats.append('ePub')
if pdf:
formats.append('PDF')
s.formats = ', '.join(formats)
yield s yield s