From 062d589f865cf736620f4ff5d6a8476dfe980ba7 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 29 Dec 2020 15:49:41 +0100 Subject: [PATCH] [fix] xpath expressions to grap all items from bandcamp's response I also found some items missing a thumbnail and I used text_extract for content and title, to remove unneeded whitespaces. BTW: added bandcamp's favicon Signed-off-by: Markus Heiser --- searx/engines/bandcamp.py | 15 ++++++++------- searx/static/themes/oscar/img/icons/bandcamp.png | Bin 0 -> 919 bytes 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 searx/static/themes/oscar/img/icons/bandcamp.png diff --git a/searx/engines/bandcamp.py b/searx/engines/bandcamp.py index b1b5214fe..dafb3ee16 100644 --- a/searx/engines/bandcamp.py +++ b/searx/engines/bandcamp.py @@ -51,19 +51,20 @@ def response(resp): tree = html.fromstring(resp.text) search_results = tree.xpath('//li[contains(@class, "searchresult")]') for result in search_results: - link = result.xpath('//div[@class="itemurl"]/a')[0] + link = result.xpath('.//div[@class="itemurl"]/a')[0] result_id = parse_qs(urlparse(link.get('href')).query)["search_item_id"][0] - title = result.xpath('//div[@class="heading"]/a/text()')[0] + title = result.xpath('.//div[@class="heading"]/a/text()') date = dateparse(result.xpath('//div[@class="released"]/text()')[0].replace("released ", "")) - content = result.xpath('//div[@class="subhead"]/text()')[0] - thumbnail = result.xpath('//div[@class="art"]/img/@src')[0] + content = result.xpath('.//div[@class="subhead"]/text()') new_result = { "url": extract_text(link), - "title": title, - "content": content, + "title": extract_text(title), + "content": extract_text(content), "publishedDate": date, - "thumbnail": thumbnail, } + thumbnail = result.xpath('.//div[@class="art"]/img/@src') + if thumbnail: + new_result['thumbnail'] = thumbnail[0] if "album" in result.classes: new_result["embedded"] = embedded_url.format(type='album', result_id=result_id) elif "track" in result.classes: diff --git a/searx/static/themes/oscar/img/icons/bandcamp.png b/searx/static/themes/oscar/img/icons/bandcamp.png new file mode 100644 index 0000000000000000000000000000000000000000..2de405afe839369f85250a04b21595bdf646aee5 GIT binary patch literal 919 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyEa{HEjtmSN`?>!lvVtU&J%W50 z7^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10;!J=~h%1nmU2s?qh!!4^ zTW~~n{vql4hvXI?m0x&7X8s|W1&8Do9g$rKlszi5;IRCnqY8_U$Spc5x9~7f7eNG6 zPf!iW_Jv2VD4Tx>iy+KWpkvTv|Ns9lH9gV;=pUz&AirQBjSiSu7(-JM5|g8S{!U^% z`SbU$Tm12V(z$M2WGfC6d-m@DW4kkx@~3sPjb<^57F{~QH95ZxXar-Dx4VmT`UT!3 zAcwug)7O>#F^eESm*kb7K?i}-;+`&!Ar`042Hgx|G8DLD*7acRNhT(4p*)wAiNPTy z|NbwYqk8&uT9&--Z^h7+FTX5Fx8nH6&yb<)u>7mALW&G>o$tvVBca36IAhucpB+cIUiYeOc*-Tbz~mk)cS^ZWK;xt0=dV9^^Jh%uh*`Vg zD{IoNH9udP3Y$zjG(lH4A&*baj=R`1;oH%7qQWN24)N>0t*mOdyzjSfsbasomd|$s zk?mL7_Z7FqO}Dyfy8Y$yP^)LFH6uD!9()$$wD;N5HBp+gfB$Jv z)-$#__NVTjUIPp@)e_f;l9a@fRIB8oR3OD*WMF8iYha>lXdYr{YGr6(Wn`*tU}R-r zuxGxXK8l9i{FKbJO57UG9{M&Js3E*6B%&lJv0R~`C_gPTCsm=OvLICRr~FT!@q8M@z^u%zm&`4!EbKj5gjra@rNQKI3bXR&5QWn>uADe>=7`J@ g_R|d>3%v9gUWp5qd~!0K3bca3)78&qol`;+0IuU@#sB~S literal 0 HcmV?d00001