mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a convenient cached CSSSelect method to jsnews
This commit is contained in:
parent
55b7bb8c25
commit
37439fecf6
@ -30,6 +30,18 @@ def image_data_to_url(data, base='cover'):
|
||||
ans.name = 'cover.' + ext
|
||||
return ans
|
||||
|
||||
css_select_cache = {}
|
||||
|
||||
def CSSSelect(expr):
|
||||
try:
|
||||
return css_select_cache[expr]
|
||||
except KeyError:
|
||||
from cssselect import HTMLTranslator
|
||||
from lxml.etree import XPath
|
||||
ans = css_select_cache[expr] = XPath(HTMLTranslator().css_to_xpath(expr))
|
||||
return ans
|
||||
|
||||
|
||||
class JavascriptRecipe(BasicNewsRecipe):
|
||||
|
||||
'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user