Parcourir la source

Merge pull request #1015 from misnyo/digg

[fix] digg now requires cookie for search
Adam Tauber il y a 7 ans
Parent
révision
610117d054
1 fichiers modifiés avec 7 ajouts et 0 suppressions
  1. 7
    0
      searx/engines/digg.py

+ 7
- 0
searx/engines/digg.py Voir le fichier

@@ -10,6 +10,8 @@
10 10
  @parse       url, title, content, publishedDate, thumbnail
11 11
 """
12 12
 
13
+import random
14
+import string
13 15
 from dateutil import parser
14 16
 from json import loads
15 17
 from lxml import html
@@ -30,12 +32,17 @@ title_xpath = './/h2//a//text()'
30 32
 content_xpath = './/p//text()'
31 33
 pubdate_xpath = './/time'
32 34
 
35
+digg_cookie_chars = string.ascii_uppercase + string.ascii_lowercase +\
36
+    string.digits + "+_"
37
+
33 38
 
34 39
 # do search-request
35 40
 def request(query, params):
36 41
     offset = (params['pageno'] - 1) * 10
37 42
     params['url'] = search_url.format(position=offset,
38 43
                                       query=quote_plus(query))
44
+    params['cookies']['frontend.auid'] = ''.join(random.choice(
45
+        digg_cookie_chars) for _ in range(22))
39 46
     return params
40 47
 
41 48