mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix Foyles to account for a complete site redesign.
This commit is contained in:
parent
b62aad8ea7
commit
9faed2137f
@ -40,32 +40,27 @@ class FoylesUKStore(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.foyles.co.uk/Public/Shop/Search.aspx?fFacetId=1015&searchBy=1&quick=true&term=' + urllib2.quote(query)
|
url = 'http://ebooks.foyles.co.uk/search_for-' + 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('//table[contains(@id, "MainContent")]/tr/td/div[contains(@class, "Item")]'):
|
for data in doc.xpath('//div[@class="doc-item"]'):
|
||||||
if counter <= 0:
|
if counter <= 0:
|
||||||
break
|
break
|
||||||
id = ''.join(data.xpath('.//a[@class="Title"]/@href')).strip()
|
id_ = ''.join(data.xpath('.//p[@class="doc-cover"]/a/@href')).strip()
|
||||||
if not id:
|
if not id_:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# filter out the audio books
|
cover_url = ''.join(data.xpath('.//p[@class="doc-cover"]/a/img/@src'))
|
||||||
if not data.xpath('boolean(.//div[@class="Relative"]/ul/li[contains(text(), "ePub")])'):
|
title = ''.join(data.xpath('.//span[@class="title"]/a/text()'))
|
||||||
continue
|
author = ', '.join(data.xpath('.//span[@class="author"]/span[@class="author"]/text()'))
|
||||||
|
price = ''.join(data.xpath('.//span[@class="price"]/text()'))
|
||||||
cover_url = ''.join(data.xpath('.//a[@class="Jacket"]/img/@src'))
|
format_ = ''.join(data.xpath('.//p[@class="doc-meta-format"]/span[last()]/text()'))
|
||||||
title = ''.join(data.xpath('.//a[@class="Title"]/text()'))
|
format_, ign, drm = format_.partition(' ')
|
||||||
author = ', '.join(data.xpath('.//span[@class="Author"]/text()'))
|
drm = SearchResult.DRM_LOCKED if 'DRM' in drm else SearchResult.DRM_UNLOCKED
|
||||||
price = ''.join(data.xpath('./ul/li[@class="Strong"]/text()'))
|
|
||||||
mo = re.search('£[\d\.]+', price)
|
|
||||||
if mo is None:
|
|
||||||
continue
|
|
||||||
price = mo.group(0)
|
|
||||||
|
|
||||||
counter -= 1
|
counter -= 1
|
||||||
|
|
||||||
@ -74,8 +69,8 @@ class FoylesUKStore(BasicStoreConfig, StorePlugin):
|
|||||||
s.title = title.strip()
|
s.title = title.strip()
|
||||||
s.author = author.strip()
|
s.author = author.strip()
|
||||||
s.price = price
|
s.price = price
|
||||||
s.detail_item = id
|
s.detail_item = id_
|
||||||
s.drm = SearchResult.DRM_LOCKED
|
s.drm = drm
|
||||||
s.formats = 'ePub'
|
s.formats = format_
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
Loading…
x
Reference in New Issue
Block a user