From f5128c7cb96d7564cc7bebeae13a319557b84aaa Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sun, 12 Feb 2017 14:58:49 +0100 Subject: [mod] add/modify image fetching for bing_news, qwant and twitter engines --- searx/engines/twitter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'searx/engines/twitter.py') diff --git a/searx/engines/twitter.py b/searx/engines/twitter.py index 038cef47f..d2a8d2088 100644 --- a/searx/engines/twitter.py +++ b/searx/engines/twitter.py @@ -27,6 +27,7 @@ search_url = base_url + 'search?' # specific xpath variables results_xpath = '//li[@data-item-type="tweet"]' +avatar_xpath = './/img[contains(@class, "avatar")]/@src' link_xpath = './/small[@class="time"]//a' title_xpath = './/span[contains(@class, "username")]' content_xpath = './/p[contains(@class, "tweet-text")]' @@ -57,6 +58,8 @@ def response(resp): try: link = tweet.xpath(link_xpath)[0] content = extract_text(tweet.xpath(content_xpath)[0]) + img_src = tweet.xpath(avatar_xpath)[0] + img_src = img_src.replace('_bigger', '_normal') except Exception: continue @@ -71,12 +74,14 @@ def response(resp): results.append({'url': url, 'title': title, 'content': content, + 'img_src': img_src, 'publishedDate': publishedDate}) else: # append result results.append({'url': url, 'title': title, - 'content': content}) + 'content': content, + 'img_src': img_src}) # return results return results -- cgit v1.2.3