mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get rid of cssselect from the amazon get books plugin
This commit is contained in:
parent
3226fb0ab4
commit
9248a9ffec
@ -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 = 7 # Needed for dynamic plugin loading
|
store_version = 8 # 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>'
|
||||||
@ -19,10 +19,6 @@ from calibre.gui2 import open_url
|
|||||||
from calibre.gui2.store import StorePlugin
|
from calibre.gui2.store import StorePlugin
|
||||||
from calibre.gui2.store.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
|
|
||||||
def CSSSelect(expr):
|
|
||||||
from cssselect import HTMLTranslator
|
|
||||||
return HTMLTranslator().css_to_xpath(expr)
|
|
||||||
|
|
||||||
def search_amazon(query, max_results=10, timeout=60,
|
def search_amazon(query, max_results=10, timeout=60,
|
||||||
write_html_to=None,
|
write_html_to=None,
|
||||||
search_url='http://www.amazon.com/s/?url=search-alias%3Ddigital-text&field-keywords='):
|
search_url='http://www.amazon.com/s/?url=search-alias%3Ddigital-text&field-keywords='):
|
||||||
@ -42,11 +38,11 @@ def search_amazon(query, max_results=10, timeout=60,
|
|||||||
return
|
return
|
||||||
|
|
||||||
if 's-result-list-parent-container' in results.get('class', ''):
|
if 's-result-list-parent-container' in results.get('class', ''):
|
||||||
data_xpath = CSSSelect('li.s-result-item')
|
data_xpath = "descendant-or-self::li[@class and contains(concat(' ', normalize-space(@class), ' '), ' s-result-item ')]"
|
||||||
format_xpath = './/a[@title="Kindle Edition"]//h3/text()'
|
format_xpath = './/a[@title="Kindle Edition"]//h3/text()'
|
||||||
asin_xpath = '@data-asin'
|
asin_xpath = '@data-asin'
|
||||||
cover_xpath = CSSSelect('img.s-access-image') + '/@src'
|
cover_xpath = "descendant-or-self::img[@class and contains(concat(' ', normalize-space(@class), ' '), ' s-access-image ')]/@src"
|
||||||
title_xpath = CSSSelect('h2.s-access-title') + '//text()'
|
title_xpath = "descendant-or-self::h2[@class and contains(concat(' ', normalize-space(@class), ' '), ' s-access-title ')]//text()"
|
||||||
author_xpath = './/span[starts-with(text(), "by ")]/following-sibling::span//text()'
|
author_xpath = './/span[starts-with(text(), "by ")]/following-sibling::span//text()'
|
||||||
price_xpath = '(.//span[contains(@class, " s-price ")])[last()]//text()'
|
price_xpath = '(.//span[contains(@class, " s-price ")])[last()]//text()'
|
||||||
elif 'grid' in results.get('class', ''):
|
elif 'grid' in results.get('class', ''):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user