mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
5a61010d9d
commit
6c224d75cf
@ -6,7 +6,6 @@ __license__ = 'GPL 3'
|
||||
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import re
|
||||
import urllib
|
||||
from contextlib import closing
|
||||
|
||||
@ -36,9 +35,9 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
|
||||
|
||||
def search(self, query, max_results=10, timeout=60):
|
||||
url = 'http://search.oreilly.com/?t1=Books&t2=Format&t3=Ebook&q=' + urllib.quote_plus(query)
|
||||
|
||||
|
||||
br = browser()
|
||||
|
||||
|
||||
counter = max_results
|
||||
with closing(br.open(url, timeout=timeout)) as f:
|
||||
doc = html.fromstring(f.read())
|
||||
@ -49,7 +48,7 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
|
||||
ebook = ' '.join(data.xpath('.//p[@class="note"]/text()'))
|
||||
if 'ebook' not in ebook.lower():
|
||||
continue
|
||||
|
||||
|
||||
id = ''.join(data.xpath('./div[@class="book_text"]//p[@class="title"]/a/@href'))
|
||||
|
||||
cover_url = ''.join(data.xpath('./a/img[1]/@src'))
|
||||
@ -61,7 +60,7 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
|
||||
# Get the detail here because we need to get the ebook id for the detail_item.
|
||||
with closing(br.open(id, timeout=timeout)) as nf:
|
||||
idoc = html.fromstring(nf.read())
|
||||
|
||||
|
||||
for td in idoc.xpath('//td[@class="optionsTd"]'):
|
||||
if 'ebook' in ''.join(td.xpath('.//text()')).lower():
|
||||
price = ''.join(td.xpath('.//span[@class="price"]/text()')).strip()
|
||||
@ -69,7 +68,7 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
|
||||
break
|
||||
|
||||
counter -= 1
|
||||
|
||||
|
||||
s = SearchResult()
|
||||
s.cover_url = cover_url.strip()
|
||||
s.title = title.strip()
|
||||
@ -78,5 +77,5 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
|
||||
s.price = price.strip()
|
||||
s.drm = SearchResult.DRM_UNLOCKED
|
||||
s.formats = formats.upper()
|
||||
|
||||
|
||||
yield s
|
||||
|
Loading…
x
Reference in New Issue
Block a user