瀏覽代碼

minor fixes of arxiv

Closes #1050
Noémi Ványi 7 年之前
父節點
當前提交
9c2b7a82f0
共有 2 個文件被更改,包括 9 次插入8 次删除
  1. 6
    5
      searx/engines/arxiv.py
  2. 3
    3
      tests/unit/engines/test_arxiv.py

+ 6
- 5
searx/engines/arxiv.py 查看文件

2
 
2
 
3
 """
3
 """
4
  ArXiV (Scientific preprints)
4
  ArXiV (Scientific preprints)
5
- @website     https://axiv.org
5
+ @website     https://arxiv.org
6
  @provide-api yes (export.arxiv.org/api/query)
6
  @provide-api yes (export.arxiv.org/api/query)
7
  @using-api   yes
7
  @using-api   yes
8
  @results     XML-RSS
8
  @results     XML-RSS
41
 def response(resp):
41
 def response(resp):
42
     results = []
42
     results = []
43
 
43
 
44
-    search_results = html.fromstring(resp.text).xpath('//entry')
44
+    dom = html.fromstring(resp.content)
45
+    search_results = dom.xpath('//entry')
45
 
46
 
46
     for entry in search_results:
47
     for entry in search_results:
47
         title = entry.xpath('.//title')[0].text
48
         title = entry.xpath('.//title')[0].text
49
         url = entry.xpath('.//id')[0].text
50
         url = entry.xpath('.//id')[0].text
50
 
51
 
51
         content_string = '{doi_content}{abstract_content}'
52
         content_string = '{doi_content}{abstract_content}'
52
-       
53
+
53
         abstract = entry.xpath('.//summary')[0].text
54
         abstract = entry.xpath('.//summary')[0].text
54
 
55
 
55
         #  If a doi is available, add it to the snipppet
56
         #  If a doi is available, add it to the snipppet
56
         try:
57
         try:
57
             doi_content = entry.xpath('.//link[@title="doi"]')[0].text
58
             doi_content = entry.xpath('.//link[@title="doi"]')[0].text
58
-            content = content_string.format(doi_content=doi_content, abstract_content=abstract_content)
59
+            content = content_string.format(doi_content=doi_content, abstract_content=abstract)
59
         except:
60
         except:
60
-            content = content_string.format(abstract_content=abstract_content)
61
+            content = content_string.format(doi_content="", abstract_content=abstract)
61
 
62
 
62
         if len(content) > 300:
63
         if len(content) > 300:
63
                     content = content[0:300] + "..."
64
                     content = content[0:300] + "..."

+ 3
- 3
tests/unit/engines/test_arxiv.py 查看文件

21
         self.assertRaises(AttributeError, arxiv.response, '')
21
         self.assertRaises(AttributeError, arxiv.response, '')
22
         self.assertRaises(AttributeError, arxiv.response, '[]')
22
         self.assertRaises(AttributeError, arxiv.response, '[]')
23
 
23
 
24
-        response = mock.Mock(text='''<?xml version="1.0" encoding="UTF-8"?>
24
+        response = mock.Mock(content=b'''<?xml version="1.0" encoding="UTF-8"?>
25
 <feed xmlns="http://www.w3.org/2005/Atom"></feed>''')
25
 <feed xmlns="http://www.w3.org/2005/Atom"></feed>''')
26
         self.assertEqual(arxiv.response(response), [])
26
         self.assertEqual(arxiv.response(response), [])
27
 
27
 
28
-        xml_mock = '''<?xml version="1.0" encoding="UTF-8"?>
28
+        xml_mock = b'''<?xml version="1.0" encoding="UTF-8"?>
29
 <feed xmlns="http://www.w3.org/2005/Atom">
29
 <feed xmlns="http://www.w3.org/2005/Atom">
30
   <title type="html">ArXiv Query: search_query=all:test_query&amp;id_list=&amp;start=0&amp;max_results=1</title>
30
   <title type="html">ArXiv Query: search_query=all:test_query&amp;id_list=&amp;start=0&amp;max_results=1</title>
31
   <id>http://arxiv.org/api/1</id>
31
   <id>http://arxiv.org/api/1</id>
50
 </feed>
50
 </feed>
51
 '''
51
 '''
52
 
52
 
53
-        response = mock.Mock(text=xml_mock.encode('utf-8'))
53
+        response = mock.Mock(content=xml_mock)
54
         results = arxiv.response(response)
54
         results = arxiv.response(response)
55
         self.assertEqual(type(results), list)
55
         self.assertEqual(type(results), list)
56
         self.assertEqual(len(results), 1)
56
         self.assertEqual(len(results), 1)