瀏覽代碼

fix bing "garbage" results (issue #1275)

Marc Abonce Seguin 6 年之前
父節點
當前提交
75b276f408
共有 2 個文件被更改,包括 6 次插入3 次删除
  1. 4
    1
      searx/engines/bing.py
  2. 2
    2
      searx/utils.py

+ 4
- 1
searx/engines/bing.py 查看文件

@@ -16,7 +16,7 @@
16 16
 from lxml import html
17 17
 from searx.engines.xpath import extract_text
18 18
 from searx.url_utils import urlencode
19
-from searx.utils import match_language
19
+from searx.utils import match_language, gen_useragent
20 20
 
21 21
 # engine dependent config
22 22
 categories = ['general']
@@ -43,6 +43,9 @@ def request(query, params):
43 43
         offset=offset)
44 44
 
45 45
     params['url'] = base_url + search_path
46
+
47
+    params['headers']['User-Agent'] = gen_useragent('Windows NT 6.3; WOW64')
48
+
46 49
     return params
47 50
 
48 51
 

+ 2
- 2
searx/utils.py 查看文件

@@ -57,9 +57,9 @@ blocked_tags = ('script',
57 57
                 'style')
58 58
 
59 59
 
60
-def gen_useragent():
60
+def gen_useragent(os=None):
61 61
     # TODO
62
-    return ua.format(os=choice(ua_os), version=choice(ua_versions))
62
+    return ua.format(os=os or choice(ua_os), version=choice(ua_versions))
63 63
 
64 64
 
65 65
 def searx_useragent():