on master help sign in
[fix] bing images page change
commit71de593a5b9025e360da32813e9efeaeaa4992b2 authorAdam Tauber <asciimoo@gmail.com> dateSat 26 Mar 2016, 02:07 (11 years ago) parent6d55642
2 files changed+10−154
searx/engines/bing_images.py+1−1 tests/unit/engines/test_bing_images.py+9−153
searx/engines/bing_images.py+1−1
@@ -69,7 +69,7 @@ def response(resp):
6969 dom = html.fromstring(resp.text)
7070
7171 # parse results
72− for result in dom.xpath('//div[@class="dg_u"]'):
72+ for result in dom.xpath('//div[@class="dg_u"]/div'):
7373 link = result.xpath('./a')[0]
7474
7575 # parse json-data (it is required to add a space, to make it parsable)
tests/unit/engines/test_bing_images.py+9−153
@@ -38,12 +38,12 @@ class TestBingImagesEngine(SearxTestCase):
3838 self.assertEqual(bing_images.response(response), [])
3939
4040 html = """
41− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
41+ <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px"><div>
4242 <a href="/images/search?q=south&amp;view=detailv2&amp;&amp;id=7E92863981CCFB89FBDD55205C742DFDA3290CF6&amp;selectedIndex=9&amp;ccid=vzvIfv5u&amp;simid=608055786735667000&amp;thid=OIP.Mbf3bc87efe6e0e476be8cc34bf6cd80eH0" ihk="OIP.Mbf3bc87efe6e0e476be8cc34bf6cd80eH0" t1="South Carolina" t2="747 x 589 &#183; 29 kB &#183; gif" t3="www.digital-topo-maps.com/county-map/south-carolina.shtml" hh="236" hw="300" m='{ns:"images",k:"5117",mid:"7E92863981CCFB89FBDD55205C742DFDA3290CF6",md5:"bf3bc87efe6e0e476be8cc34bf6cd80e",surl:"http://www.digital-topo-maps.com/county-map/south-carolina.shtml",imgurl:"http://www.digital-topo-maps.com/county-map/south-carolina-county-map.gif",tid:"OIP.Mbf3bc87efe6e0e476be8cc34bf6cd80eH0",ow:"480",docid:"608055786735667000",oh:"378",tft:"45"}' mid="7E92863981CCFB89FBDD55205C742DFDA3290CF6" h="ID=images,5117.1">
4343 <img class="img_hid" src2="https://tse4.mm.bing.net/th?id=OIP.Mbf3bc87efe6e0e476be8cc34bf6cd80eH0&amp;w=210&amp;h=154&amp;c=7&amp;rs=1&amp;qlt=90&amp;o=4&amp;pid=1.1" style="width:210px;height:154px;" width="210" height="154">
4444 </a>
4545
46− </div>
46+ </div></div>
4747 """ # noqa
4848 html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
4949 response = mock.Mock(text=html)
@@ -78,7 +78,7 @@ class TestBingImagesEngine(SearxTestCase):
7878 self.assertEqual(len(results), 0)
7979
8080 html = """
81− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
81+ <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px"><div>
8282 <a href="#" ihk="HN.608003696942779811"
8383 m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
8484mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
@@ -89,8 +89,8 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
8989 <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
9090 style="height:144px;" width="178" height="144"/>
9191 </a>
92− </div>
93− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
92+ </div></div>
93+ <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px"><div>
9494 <a href="#" ihk="HN.608003696942779811"
9595 m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
9696mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
@@ -101,8 +101,8 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
101101 <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
102102 style="height:144px;" width="178" height="144"/>
103103 </a>
104− </div>
105− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
104+ </div></div>
105+ <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px"><div>
106106 <a href="#" ihk="HN.608003696942779811"
107107 m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
108108mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
@@ -113,154 +113,10 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
113113 <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
114114 style="height:144px;" width="178" height="144"/>
115115 </a>
116− </div>
117− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
118− <a href="#" ihk="HN.608003696942779811"
119− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
120−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
121−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
122−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
123− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
124− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
125− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
126− style="height:144px;" width="178" height="144"/>
127− </a>
128− </div>
129− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
130− <a href="#" ihk="HN.608003696942779811"
131− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
132−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
133−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
134−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
135− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
136− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
137− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
138− style="height:144px;" width="178" height="144"/>
139− </a>
140− </div>
141− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
142− <a href="#" ihk="HN.608003696942779811"
143− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
144−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
145−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
146−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
147− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
148− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
149− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
150− style="height:144px;" width="178" height="144"/>
151− </a>
152− </div>
153− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
154− <a href="#" ihk="HN.608003696942779811"
155− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
156−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
157−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
158−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
159− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
160− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
161− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
162− style="height:144px;" width="178" height="144"/>
163− </a>
164− </div>
165− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
166− <a href="#" ihk="HN.608003696942779811"
167− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
168−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
169−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
170−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
171− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
172− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
173− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
174− style="height:144px;" width="178" height="144"/>
175− </a>
176− </div>
177− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
178− <a href="#" ihk="HN.608003696942779811"
179− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
180−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
181−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
182−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
183− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
184− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
185− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
186− style="height:144px;" width="178" height="144"/>
187− </a>
188− </div>
189− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
190− <a href="#" ihk="HN.608003696942779811"
191− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
192−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
193−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
194−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
195− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
196− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
197− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
198− style="height:144px;" width="178" height="144"/>
199− </a>
200− </div>
201− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
202− <a href="#" ihk="HN.608003696942779811"
203− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
204−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
205−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
206−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
207− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
208− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
209− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
210− style="height:144px;" width="178" height="144"/>
211− </a>
212− </div>
213− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
214− <a href="#" ihk="HN.608003696942779811"
215− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
216−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
217−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
218−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
219− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
220− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
221− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
222− style="height:144px;" width="178" height="144"/>
223− </a>
224− </div>
225− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
226− <a href="#" ihk="HN.608003696942779811"
227− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
228−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
229−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
230−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
231− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
232− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
233− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
234− style="height:144px;" width="178" height="144"/>
235− </a>
236− </div>
237− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
238− <a href="#" ihk="HN.608003696942779811"
239− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
240−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
241−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
242−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
243− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
244− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
245− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
246− style="height:144px;" width="178" height="144"/>
247− </a>
248− </div>
249− <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
250− <a href="#" ihk="HN.608003696942779811"
251− m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
252−mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
253−surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
254−oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
255− mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
256− t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
257− <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
258− style="height:144px;" width="178" height="144"/>
259− </a>
260− </div>
116+ </div></div>
261117 """
262118 html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
263119 response = mock.Mock(text=html)
264120 results = bing_images.response(response)
265121 self.assertEqual(type(results), list)
266− self.assertEqual(len(results), 10)
122+ self.assertEqual(len(results), 3)