forked from Ponysearch/Ponysearch
[fix] ddg-lite vqd value: some search terms do not have a vqd value
Some search terms do not have results and therefore no vqd value
BTW: remove a leftover from 9197efa
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
9197efa2a7
commit
3388441917
1 changed files with 6 additions and 4 deletions
|
@ -98,7 +98,12 @@ def get_vqd(query):
|
||||||
query_url = 'https://lite.duckduckgo.com/lite/?{args}'.format(args=urlencode({'q': query}))
|
query_url = 'https://lite.duckduckgo.com/lite/?{args}'.format(args=urlencode({'q': query}))
|
||||||
res = get(query_url)
|
res = get(query_url)
|
||||||
doc = lxml.html.fromstring(res.text)
|
doc = lxml.html.fromstring(res.text)
|
||||||
value = doc.xpath("//input[@name='vqd']/@value")[0]
|
value = doc.xpath("//input[@name='vqd']/@value")
|
||||||
|
if value:
|
||||||
|
value = value[0]
|
||||||
|
else:
|
||||||
|
# some search terms do not have results and therefore no vqd value
|
||||||
|
value = ''
|
||||||
logger.debug("new vqd value: %s", value)
|
logger.debug("new vqd value: %s", value)
|
||||||
cache_vqd(query, value)
|
cache_vqd(query, value)
|
||||||
return value
|
return value
|
||||||
|
@ -236,9 +241,6 @@ def request(query, params):
|
||||||
params['data']['s'] = offset
|
params['data']['s'] = offset
|
||||||
params['data']['dc'] = offset + 1
|
params['data']['dc'] = offset + 1
|
||||||
|
|
||||||
# request needs a vqd argument
|
|
||||||
params['data']['vqd'] = get_vqd(query)
|
|
||||||
|
|
||||||
# initial page does not have additional data in the input form
|
# initial page does not have additional data in the input form
|
||||||
if params['pageno'] > 1:
|
if params['pageno'] > 1:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue