on master help sign in
Merge branch 'master' into master
commitaeb6dab1872921fc129d47830620ae78bc185e53 authorNoémi Ványi <kvch@users.noreply.github.com> dateFri 4 Jan 2019, 22:14 (8 years ago) parent0d86ed982bf9c6
4 files changed+19−20
searx/engines/bing_images.py+1−3 searx/engines/startpage.py+4−3 tests/unit/engines/test_bing_images.py+3−3 tests/unit/engines/test_startpage.py+11−11
searx/engines/bing_images.py+1−3
@@ -88,9 +88,7 @@ def response(resp):
8888
8989 url = json_data.get('purl')
9090 img_src = json_data.get('murl')
91−
92− thumb_json_data = loads(_quote_keys_regex.sub(r'\1"\2": \3', link.attrib.get('mad')))
93− thumbnail = thumb_json_data.get('turl')
91+ thumbnail = json_data.get('turl')
9492
9593 # append result
9694 results.append({'template': 'images.html',
searx/engines/startpage.py+4−3
@@ -32,8 +32,9 @@ search_url = base_url + 'do/search'
3232# specific xpath variables
3333# ads xpath //div[@id="results"]/div[@id="sponsored"]//div[@class="result"]
3434# not ads: div[@class="result"] are the direct childs of div[@id="results"]
35−results_xpath = '//div[@class="result"]'
35+results_xpath = '//li[contains(@class, "search-result") and contains(@class, "search-item")]'
3636link_xpath = './/h3/a'
37+content_xpath = './p[@class="search-item__body"]'
3738
3839
3940# do search-request
@@ -75,8 +76,8 @@ def response(resp):
7576
7677 title = extract_text(link)
7778
78− if result.xpath('./p[@class="desc clk"]'):
79− content = extract_text(result.xpath('./p[@class="desc clk"]'))
79+ if result.xpath(content_xpath):
80+ content = extract_text(result.xpath(content_xpath))
8081 else:
8182 content = ''
8283
tests/unit/engines/test_bing_images.py+3−3
@@ -52,7 +52,7 @@ class TestBingImagesEngine(SearxTestCase):
5252 <li>
5353 <div>
5454 <div class="imgpt">
55− <a m='{"purl":"page_url","murl":"img_url"}' mad='{"turl":"thumb_url"}'>
55+ <a m='{"purl":"page_url","murl":"img_url","turl":"thumb_url"}'>
5656 <img src="" alt="alt text" />
5757 </a>
5858 </div>
@@ -60,7 +60,7 @@ class TestBingImagesEngine(SearxTestCase):
6060 </div>
6161 <div>
6262 <div class="imgpt">
63− <a m='{"purl":"page_url2","murl":"img_url2"}' mad='{"turl":"thumb_url2"}'>
63+ <a m='{"purl":"page_url2","murl":"img_url2","turl":"thumb_url2"}'>
6464 <img src="" alt="alt text 2" />
6565 </a>
6666 </div>
@@ -71,7 +71,7 @@ class TestBingImagesEngine(SearxTestCase):
7171 <li>
7272 <div>
7373 <div class="imgpt">
74− <a m='{"purl":"page_url3","murl":"img_url3"}' mad='{"turl":"thumb_url3"}'>
74+ <a m='{"purl":"page_url3","murl":"img_url3","turl":"thumb_url3"}'>
7575 <img src="" alt="alt text 3" />
7676 </a>
7777 </div>
tests/unit/engines/test_startpage.py+11−11
@@ -31,14 +31,14 @@ class TestStartpageEngine(SearxTestCase):
3131 self.assertEqual(startpage.response(response), [])
3232
3333 html = """
34− <div class='result' style=' *width : auto; *margin-right : 10%;'>
34+ <li class="search-result search-item">
3535 <h3>
3636 <a href='http://this.should.be.the.link/' id='title_2' name='title_2' >
3737 This should be the title
3838 </a>
3939 <span id='title_stars_2' name='title_stars_2'> </span>
4040 </h3>
41− <p class='desc clk'>
41+ <p class="search-item__body">
4242 This should be the content.
4343 </p>
4444 <p>
@@ -56,7 +56,7 @@ class TestStartpageEngine(SearxTestCase):
5656 Mis en surbrillance
5757 </A>
5858 </p>
59− </div>
59+ </li>
6060 """
6161 response = mock.Mock(text=html.encode('utf-8'))
6262 results = startpage.response(response)
@@ -67,14 +67,14 @@ class TestStartpageEngine(SearxTestCase):
6767 self.assertEqual(results[0]['content'], 'This should be the content.')
6868
6969 html = """
70− <div class='result' style=' *width : auto; *margin-right : 10%;'>
70+ <li class="search-result search-item">
7171 <h3>
7272 <a href='http://www.google.com/aclk?sa=l&ai=C' id='title_2' name='title_2' >
7373 This should be the title
7474 </a>
7575 <span id='title_stars_2' name='title_stars_2'> </span>
7676 </h3>
77− <p class='desc clk'>
77+ <p class="search-item__body">
7878 This should be the content.
7979 </p>
8080 <p>
@@ -92,20 +92,20 @@ class TestStartpageEngine(SearxTestCase):
9292 Mis en surbrillance
9393 </A>
9494 </p>
95− </div>
96− <div class='result' style=' *width : auto; *margin-right : 10%;'>
95+ </li>
96+ <li class="search-result search-item">
9797 <h3>
9898 <span id='title_stars_2' name='title_stars_2'> </span>
9999 </h3>
100− <p class='desc clk'>
100+ <p class="search-item__body">
101101 This should be the content.
102102 </p>
103103 <p>
104104 <span class='url'>www.speed<b>test</b>.net/fr/
105105 </span>
106106 </p>
107− </div>
108− <div class='result' style=' *width : auto; *margin-right : 10%;'>
107+ </li>
108+ <li class="search-result search-item">
109109 <h3>
110110 <a href='http://this.should.be.the.link/' id='title_2' name='title_2' >
111111 This should be the title
@@ -127,7 +127,7 @@ class TestStartpageEngine(SearxTestCase):
127127 Mis en surbrillance
128128 </A>
129129 </p>
130− </div>
130+ </li>
131131 """
132132 response = mock.Mock(text=html.encode('utf-8'))
133133 results = startpage.response(response)