on master help sign in
Add paging support to XPath & Erowid engines
commitbacc9a3df156605c49fb93ede6e6a730110d15db authorKirill Isakov <ukwt@ya.ru> dateMon 28 Mar 2016, 19:15 (11 years ago) parente202c6f
2 files changed+19−2
searx/engines/xpath.py+15−1 searx/settings.yml+4−1
searx/engines/xpath.py+15−1
@@ -11,6 +11,14 @@ title_xpath = None
1111suggestion_xpath = ''
1212results_xpath = ''
1313
14+# parameters for engines with paging support
15+#
16+# number of results on each page
17+# (only needed if the site requires not a page number, but an offset)
18+page_size = 1
19+# number of the first page (usually 0 or 1)
20+first_page_num = 1
21+
1422
1523'''
1624if xpath_results is list, extract the text from each result and concat the list
@@ -76,8 +84,14 @@ def normalize_url(url):
7684
7785def request(query, params):
7886 query = urlencode({'q': query})[2:]
79− params['url'] = search_url.format(query=query)
87+
88+ fp = {'query': query}
89+ if paging and search_url.find('{pageno}') >= 0:
90+ fp['pageno'] = (params['pageno'] + first_page_num - 1) * page_size
91+
92+ params['url'] = search_url.format(**fp)
8093 params['query'] = query
94+
8195 return params
8296
8397
searx/settings.yml+4−1
@@ -84,7 +84,10 @@ engines:
8484
8585 - name : erowid
8686 engine : xpath
87− search_url : https://www.erowid.org/search.php?q={query}
87+ paging : True
88+ first_page_num : 0
89+ page_size : 30
90+ search_url : https://www.erowid.org/search.php?q={query}&s={pageno}
8891 url_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/@href
8992 title_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/text()
9093 content_xpath : //dl[@class="results-list"]/dd[@class="result-details"]