Quellcode durchsuchen

Add paging support to XPath & Erowid engines

Kirill Isakov vor 9 Jahren
Ursprung
Commit
bacc9a3df1
2 geänderte Dateien mit 19 neuen und 2 gelöschten Zeilen
  1. 15
    1
      searx/engines/xpath.py
  2. 4
    1
      searx/settings.yml

+ 15
- 1
searx/engines/xpath.py Datei anzeigen

11
 suggestion_xpath = ''
11
 suggestion_xpath = ''
12
 results_xpath = ''
12
 results_xpath = ''
13
 
13
 
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
+
14
 
22
 
15
 '''
23
 '''
16
 if xpath_results is list, extract the text from each result and concat the list
24
 if xpath_results is list, extract the text from each result and concat the list
76
 
84
 
77
 def request(query, params):
85
 def request(query, params):
78
     query = urlencode({'q': query})[2:]
86
     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)
80
     params['query'] = query
93
     params['query'] = query
94
+
81
     return params
95
     return params
82
 
96
 
83
 
97
 

+ 4
- 1
searx/settings.yml Datei anzeigen

84
 
84
 
85
   - name : erowid
85
   - name : erowid
86
     engine : xpath
86
     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}
88
     url_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/@href
91
     url_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/@href
89
     title_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/text()
92
     title_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/text()
90
     content_xpath : //dl[@class="results-list"]/dd[@class="result-details"]
93
     content_xpath : //dl[@class="results-list"]/dd[@class="result-details"]