Merge pull request #1464 from miicha/bugfix_startpage

restore startpage search results
This commit is contained in:
Noémi Ványi 2019-01-04 22:10:38 +01:00 committed by GitHub
commit 82bf9c6b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View File

@ -32,8 +32,9 @@ search_url = base_url + 'do/search'
# specific xpath variables
# ads xpath //div[@id="results"]/div[@id="sponsored"]//div[@class="result"]
# not ads: div[@class="result"] are the direct childs of div[@id="results"]
results_xpath = '//div[@class="result"]'
results_xpath = '//li[contains(@class, "search-result") and contains(@class, "search-item")]'
link_xpath = './/h3/a'
content_xpath = './p[@class="search-item__body"]'
# do search-request
@ -79,8 +80,8 @@ def response(resp):
title = extract_text(link)
if result.xpath('./p[@class="desc clk"]'):
content = extract_text(result.xpath('./p[@class="desc clk"]'))
if result.xpath(content_xpath):
content = extract_text(result.xpath(content_xpath))
else:
content = ''

View File

@ -31,14 +31,14 @@ class TestStartpageEngine(SearxTestCase):
self.assertEqual(startpage.response(response), [])
html = """
<div class='result' style=' *width : auto; *margin-right : 10%;'>
<li class="search-result search-item">
<h3>
<a href='http://this.should.be.the.link/' id='title_2' name='title_2' >
This should be the title
</a>
<span id='title_stars_2' name='title_stars_2'> </span>
</h3>
<p class='desc clk'>
<p class="search-item__body">
This should be the content.
</p>
<p>
@ -56,7 +56,7 @@ class TestStartpageEngine(SearxTestCase):
Mis en surbrillance
</A>
</p>
</div>
</li>
"""
response = mock.Mock(text=html.encode('utf-8'))
results = startpage.response(response)
@ -67,14 +67,14 @@ class TestStartpageEngine(SearxTestCase):
self.assertEqual(results[0]['content'], 'This should be the content.')
html = """
<div class='result' style=' *width : auto; *margin-right : 10%;'>
<li class="search-result search-item">
<h3>
<a href='http://www.google.com/aclk?sa=l&ai=C' id='title_2' name='title_2' >
This should be the title
</a>
<span id='title_stars_2' name='title_stars_2'> </span>
</h3>
<p class='desc clk'>
<p class="search-item__body">
This should be the content.
</p>
<p>
@ -92,20 +92,20 @@ class TestStartpageEngine(SearxTestCase):
Mis en surbrillance
</A>
</p>
</div>
<div class='result' style=' *width : auto; *margin-right : 10%;'>
</li>
<li class="search-result search-item">
<h3>
<span id='title_stars_2' name='title_stars_2'> </span>
</h3>
<p class='desc clk'>
<p class="search-item__body">
This should be the content.
</p>
<p>
<span class='url'>www.speed<b>test</b>.net/fr/
</span>
</p>
</div>
<div class='result' style=' *width : auto; *margin-right : 10%;'>
</li>
<li class="search-result search-item">
<h3>
<a href='http://this.should.be.the.link/' id='title_2' name='title_2' >
This should be the title
@ -127,7 +127,7 @@ class TestStartpageEngine(SearxTestCase):
Mis en surbrillance
</A>
</p>
</div>
</li>
"""
response = mock.Mock(text=html.encode('utf-8'))
results = startpage.response(response)