瀏覽代碼

[fix] bing images page change

Adam Tauber 9 年之前
父節點
當前提交
71de593a5b
共有 2 個檔案被更改,包括 10 行新增154 行删除
  1. 1
    1
      searx/engines/bing_images.py
  2. 9
    153
      tests/unit/engines/test_bing_images.py

+ 1
- 1
searx/engines/bing_images.py 查看文件

@@ -69,7 +69,7 @@ def response(resp):
69 69
     dom = html.fromstring(resp.text)
70 70
 
71 71
     # parse results
72
-    for result in dom.xpath('//div[@class="dg_u"]'):
72
+    for result in dom.xpath('//div[@class="dg_u"]/div'):
73 73
         link = result.xpath('./a')[0]
74 74
 
75 75
         # parse json-data (it is required to add a space, to make it parsable)

+ 9
- 153
tests/unit/engines/test_bing_images.py 查看文件

@@ -38,12 +38,12 @@ class TestBingImagesEngine(SearxTestCase):
38 38
         self.assertEqual(bing_images.response(response), [])
39 39
 
40 40
         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>
42 42
             <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">
43 43
                 <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">
44 44
             </a>
45 45
 
46
-        </div>
46
+        </div></div>
47 47
         """  # noqa
48 48
         html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
49 49
         response = mock.Mock(text=html)
@@ -78,7 +78,7 @@ class TestBingImagesEngine(SearxTestCase):
78 78
         self.assertEqual(len(results), 0)
79 79
 
80 80
         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>
82 82
             <a href="#" ihk="HN.608003696942779811"
83 83
                 m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
84 84
 mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
@@ -89,8 +89,8 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
89 89
                 <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
90 90
                 style="height:144px;" width="178" height="144"/>
91 91
             </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>
94 94
             <a href="#" ihk="HN.608003696942779811"
95 95
                 m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
96 96
 mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
@@ -101,8 +101,8 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
101 101
                 <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
102 102
                 style="height:144px;" width="178" height="144"/>
103 103
             </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>
106 106
             <a href="#" ihk="HN.608003696942779811"
107 107
                 m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
108 108
 mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
@@ -113,154 +113,10 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
113 113
                 <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
114 114
                 style="height:144px;" width="178" height="144"/>
115 115
             </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>
261 117
         """
262 118
         html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
263 119
         response = mock.Mock(text=html)
264 120
         results = bing_images.response(response)
265 121
         self.assertEqual(type(results), list)
266
-        self.assertEqual(len(results), 10)
122
+        self.assertEqual(len(results), 3)