Repository: searx/searx

Issue:
Searx.me Person Information Missing Picture 
I noticed recently that if you search for example "Bill Gates" or another famous person, if you check the right area where there is Wikipedia info and a picture at the top, the picture is missing, it is corrupted.


Discussion:
Indeed I have the same problem on a v14 instance but [laquadrature](https://searx.laquadrature.net/) doesn't have this problem and is currently running searx v13.1.

After a quick look it might come from [this line](https://github.com/asciimoo/searx/blob/e5def5b0191a36315d300457cdfdf68aebbc9a4c/searx/engines/wikidata.py#L40). I think the `filename` variable is incorrect, it should stop after the type (`.jpg`in my test) but seems to be a bit longer and contains some metadata about the image.

I'll try to take a deeper look later.

Resolving patch:
diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py
--- a/searx/engines/wikidata.py
+++ b/searx/engines/wikidata.py
@@ -54,6 +54,7 @@
     + '/*/div[contains(@class,"wikibase-snakview-value")]'
 language_fallback_xpath = '//sup[contains(@class,"wb-language-fallback-indicator")]'
 calendar_name_xpath = './/sup[contains(@class,"wb-calendar-name")]'
+media_xpath = value_xpath + '//div[contains(@class,"commons-media-caption")]//a'
 
 
 def request(query, params):
@@ -313,7 +314,7 @@ def add_image(result):
     for property_id in property_ids:
         image = result.xpath(property_xpath.replace('{propertyid}', property_id))
         if image:
-            image_name = image[0].xpath(value_xpath)
+            image_name = image[0].xpath(media_xpath)
             image_src = url_image.replace('{filename}', extract_text(image_name[0]))
             return image_src
 


Test patch:
diff --git a/tests/unit/engines/test_wikidata.py b/tests/unit/engines/test_wikidata.py
--- a/tests/unit/engines/test_wikidata.py
+++ b/tests/unit/engines/test_wikidata.py
@@ -123,9 +123,10 @@ def test_add_image(self):
                         <div class="wikibase-statementview-mainsnak">
                             <div>
                                 <div class="wikibase-snakview-value">
-                                    <a href="https://commons.wikimedia.org/wiki/File:image.png">
-                                        image.png
-                                    </a>
+                                    <div class="commons-media-caption">
+                                        <a href="https://commons.wikimedia.org/wiki/File:image.png">image.png</a>
+                                        <br/>2,687 &#215; 3,356; 1.22 MB
+                                    </div>
                                 </div>
                             </div>
                         </div>
@@ -156,9 +157,10 @@ def test_add_image(self):
                         <div class="wikibase-statementview-mainsnak">
                             <div>
                                 <div class="wikibase-snakview-value">
-                                    <a href="https://commons.wikimedia.org/wiki/File:icon.png">
-                                        icon.png
-                                    </a>
+                                    <div class="commons-media-caption">
+                                        <a href="https://commons.wikimedia.org/wiki/File:icon.png">icon.png</a>
+                                        <br/>671 &#215; 671; 18 KB</div>
+                                    </div>
                                 </div>
                             </div>
                         </div>
@@ -179,9 +181,10 @@ def test_add_image(self):
                         <div class="wikibase-statementview-mainsnak">
                             <div>
                                 <div class="wikibase-snakview-value">
-                                    <a href="https://commons.wikimedia.org/wiki/File:logo.png">
-                                        logo.png
-                                    </a>
+                                    <div class="commons-media-caption">
+                                        <a href="https://commons.wikimedia.org/wiki/File:logo.png">logo.png</a>
+                                        <br/>170 &#215; 170; 1 KB
+                                    </div>
                                 </div>
                             </div>
                         </div>