on master help sign in
minor fixes of arxiv

Closes #1050

commit9c2b7a82f0c515fd1df88ed80349eda7f49e0825 authorNoémi Ványi <sitbackandwait@gmail.com> dateWed 1 Nov 2017, 12:28 (9 years ago) parente391b2d
2 files changed+9−8
searx/engines/arxiv.py+6−5 tests/unit/engines/test_arxiv.py+3−3
searx/engines/arxiv.py+6−5
@@ -2,7 +2,7 @@
22
33"""
44 ArXiV (Scientific preprints)
5− @website https://axiv.org
5+ @website https://arxiv.org
66 @provide-api yes (export.arxiv.org/api/query)
77 @using-api yes
88 @results XML-RSS
@@ -41,7 +41,8 @@ def request(query, params):
4141def response(resp):
4242 results = []
4343
44− search_results = html.fromstring(resp.text).xpath('//entry')
44+ dom = html.fromstring(resp.content)
45+ search_results = dom.xpath('//entry')
4546
4647 for entry in search_results:
4748 title = entry.xpath('.//title')[0].text
@@ -49,15 +50,15 @@ def response(resp):
4950 url = entry.xpath('.//id')[0].text
5051
5152 content_string = '{doi_content}{abstract_content}'
52−
53+
5354 abstract = entry.xpath('.//summary')[0].text
5455
5556 # If a doi is available, add it to the snipppet
5657 try:
5758 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)
5960 except:
60− content = content_string.format(abstract_content=abstract_content)
61+ content = content_string.format(doi_content="", abstract_content=abstract)
6162
6263 if len(content) > 300:
6364 content = content[0:300] + "..."
tests/unit/engines/test_arxiv.py+3−3
@@ -21,11 +21,11 @@ class TestBaseEngine(SearxTestCase):
2121 self.assertRaises(AttributeError, arxiv.response, '')
2222 self.assertRaises(AttributeError, arxiv.response, '[]')
2323
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"?>
2525<feed xmlns="http://www.w3.org/2005/Atom"></feed>''')
2626 self.assertEqual(arxiv.response(response), [])
2727
28− xml_mock = '''<?xml version="1.0" encoding="UTF-8"?>
28+ xml_mock = b'''<?xml version="1.0" encoding="UTF-8"?>
2929<feed xmlns="http://www.w3.org/2005/Atom">
3030 <title type="html">ArXiv Query: search_query=all:test_query&amp;id_list=&amp;start=0&amp;max_results=1</title>
3131 <id>http://arxiv.org/api/1</id>
@@ -50,7 +50,7 @@ class TestBaseEngine(SearxTestCase):
5050</feed>
5151'''
5252
53− response = mock.Mock(text=xml_mock.encode('utf-8'))
53+ response = mock.Mock(content=xml_mock)
5454 results = arxiv.response(response)
5555 self.assertEqual(type(results), list)
5656 self.assertEqual(len(results), 1)