mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
fix: move exception. Delegate encoding to lxml if not specified
This commit is contained in:
parent
8085b7b12a
commit
6d4a90e8d1
1 changed files with 8 additions and 9 deletions
|
@ -14,18 +14,17 @@ async def get_version(name, conf, *, cache, **kwargs):
|
|||
|
||||
async def get_version_impl(info):
|
||||
conf = dict(info)
|
||||
encoding = conf.get('encoding', 'latin1')
|
||||
|
||||
encoding = conf.get('encoding')
|
||||
parser = html.HTMLParser(encoding=encoding)
|
||||
res = await session.get(conf['url'])
|
||||
body = html.fromstring(res.body.decode(encoding))
|
||||
doc = html.fromstring(res.body, base_url=conf['url'], parser=parser)
|
||||
|
||||
try:
|
||||
checkxpath = body.xpath(conf.get('xpath'))
|
||||
except etree.XPathEvalError as e:
|
||||
raise GetVersionError('bad xpath', exc_info=e)
|
||||
|
||||
try:
|
||||
version = body.xpath(conf.get('xpath'))
|
||||
version = doc.xpath(conf.get('xpath'))
|
||||
except ValueError:
|
||||
if not conf.get('missing_ok', False):
|
||||
raise GetVersionError('version string not found.')
|
||||
return version
|
||||
except etree.XPathEvalError as e:
|
||||
raise GetVersionError('bad xpath', exc_info=e)
|
||||
return version
|
||||
|
|
Loading…
Add table
Reference in a new issue