mirror of
https://github.com/searxng/searxng.git
synced 2026-06-22 17:48:33 +02:00
Compare commits
3 Commits
afafca93f3
...
dce3bb69bb
| Author | SHA1 | Date | |
|---|---|---|---|
| dce3bb69bb | |||
| de49d27846 | |||
| 16a7537bfd |
@@ -1,75 +0,0 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
"""Ask.com"""
|
|
||||||
|
|
||||||
from urllib.parse import urlencode
|
|
||||||
import dateutil
|
|
||||||
from lxml import html
|
|
||||||
from searx import utils
|
|
||||||
|
|
||||||
# Metadata
|
|
||||||
about = {
|
|
||||||
"website": "https://www.ask.com/",
|
|
||||||
"wikidata_id": 'Q847564',
|
|
||||||
"official_api_documentation": None,
|
|
||||||
"use_official_api": False,
|
|
||||||
"require_api_key": False,
|
|
||||||
"results": "HTML",
|
|
||||||
}
|
|
||||||
|
|
||||||
# Engine Configuration
|
|
||||||
categories = ['general']
|
|
||||||
paging = True
|
|
||||||
max_page = 5
|
|
||||||
"""Ask.com has at max 5 pages."""
|
|
||||||
|
|
||||||
# Base URL
|
|
||||||
base_url = "https://www.ask.com/web"
|
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
|
||||||
|
|
||||||
query_params = {
|
|
||||||
"q": query,
|
|
||||||
"page": params["pageno"],
|
|
||||||
}
|
|
||||||
|
|
||||||
params["url"] = f"{base_url}?{urlencode(query_params)}"
|
|
||||||
return params
|
|
||||||
|
|
||||||
|
|
||||||
def response(resp):
|
|
||||||
|
|
||||||
start_tag = 'window.MESON.initialState = {'
|
|
||||||
end_tag = '}};'
|
|
||||||
|
|
||||||
dom = html.fromstring(resp.text)
|
|
||||||
script = utils.eval_xpath_getindex(dom, '//script', 0, default=None).text
|
|
||||||
|
|
||||||
pos = script.index(start_tag) + len(start_tag) - 1
|
|
||||||
script = script[pos:]
|
|
||||||
pos = script.index(end_tag) + len(end_tag) - 1
|
|
||||||
script = script[:pos]
|
|
||||||
|
|
||||||
json_resp = utils.js_obj_str_to_python(script)
|
|
||||||
|
|
||||||
results = []
|
|
||||||
|
|
||||||
for item in json_resp['search']['webResults']['results']:
|
|
||||||
|
|
||||||
pubdate_original = item.get('pubdate_original')
|
|
||||||
if pubdate_original:
|
|
||||||
pubdate_original = dateutil.parser.parse(pubdate_original)
|
|
||||||
metadata = [item.get(field) for field in ['category_l1', 'catsy'] if item.get(field)]
|
|
||||||
|
|
||||||
results.append(
|
|
||||||
{
|
|
||||||
"url": item['url'].split('&ueid')[0],
|
|
||||||
"title": item['title'],
|
|
||||||
"content": item['abstract'],
|
|
||||||
"publishedDate": pubdate_original,
|
|
||||||
# "thumbnail": item.get('image_url') or None, # these are not thumbs / to large
|
|
||||||
"metadata": ' | '.join(metadata),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return results
|
|
||||||
+12
-11
@@ -87,7 +87,6 @@ def request(query, params):
|
|||||||
|
|
||||||
def response(resp):
|
def response(resp):
|
||||||
if search_type == 'web':
|
if search_type == 'web':
|
||||||
|
|
||||||
catch_bad_response(resp)
|
catch_bad_response(resp)
|
||||||
|
|
||||||
dom = html.fromstring(resp.text)
|
dom = html.fromstring(resp.text)
|
||||||
@@ -106,7 +105,6 @@ def response(resp):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
if search_type == 'images':
|
if search_type == 'images':
|
||||||
|
|
||||||
catch_bad_response(resp)
|
catch_bad_response(resp)
|
||||||
|
|
||||||
html_data = html.fromstring(resp.text)
|
html_data = html.fromstring(resp.text)
|
||||||
@@ -127,22 +125,25 @@ def response(resp):
|
|||||||
for _, item_data in json_resp['initialState']['serpList']['items']['entities'].items():
|
for _, item_data in json_resp['initialState']['serpList']['items']['entities'].items():
|
||||||
title = item_data['snippet']['title']
|
title = item_data['snippet']['title']
|
||||||
source = item_data['snippet']['url']
|
source = item_data['snippet']['url']
|
||||||
thumb = item_data['image']
|
|
||||||
fullsize_image = item_data['viewerData']['dups'][0]['url']
|
image_source = item_data["viewerData"]["thumb"]
|
||||||
height = item_data['viewerData']['dups'][0]['h']
|
for i in item_data['viewerData']['dups'] + item_data['viewerData']['preview']:
|
||||||
width = item_data['viewerData']['dups'][0]['w']
|
if i["h"] > image_source["h"]:
|
||||||
filesize = item_data['viewerData']['dups'][0]['fileSizeInBytes']
|
image_source = i
|
||||||
humanized_filesize = humanize_bytes(filesize)
|
|
||||||
|
humanized_filesize = None
|
||||||
|
if image_source.get("fileSizeInBytes"):
|
||||||
|
humanized_filesize = humanize_bytes(image_source["fileSizeInBytes"])
|
||||||
|
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
'title': title,
|
'title': title,
|
||||||
'url': source,
|
'url': source,
|
||||||
'img_src': fullsize_image,
|
'img_src': image_source["url"],
|
||||||
'filesize': humanized_filesize,
|
'filesize': humanized_filesize,
|
||||||
'thumbnail_src': thumb,
|
'thumbnail_src': item_data["image"],
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
'resolution': f'{width} x {height}',
|
'resolution': f'{image_source["w"]} x {image_source["h"]}',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -469,11 +469,6 @@ engines:
|
|||||||
engine: arxiv
|
engine: arxiv
|
||||||
shortcut: arx
|
shortcut: arx
|
||||||
|
|
||||||
- name: ask
|
|
||||||
engine: ask
|
|
||||||
shortcut: ask
|
|
||||||
disabled: true
|
|
||||||
|
|
||||||
- name: azure
|
- name: azure
|
||||||
engine: azure
|
engine: azure
|
||||||
shortcut: az
|
shortcut: az
|
||||||
@@ -1203,6 +1198,7 @@ engines:
|
|||||||
categories: [general, web]
|
categories: [general, web]
|
||||||
search_type: web
|
search_type: web
|
||||||
shortcut: ka
|
shortcut: ka
|
||||||
|
inactive: true
|
||||||
|
|
||||||
- name: karmasearch images
|
- name: karmasearch images
|
||||||
engine: karmasearch
|
engine: karmasearch
|
||||||
@@ -1210,18 +1206,21 @@ engines:
|
|||||||
search_type: images
|
search_type: images
|
||||||
shortcut: kai
|
shortcut: kai
|
||||||
paging: false
|
paging: false
|
||||||
|
inactive: true
|
||||||
|
|
||||||
- name: karmasearch videos
|
- name: karmasearch videos
|
||||||
engine: karmasearch
|
engine: karmasearch
|
||||||
categories: [videos, web]
|
categories: [videos, web]
|
||||||
search_type: videos
|
search_type: videos
|
||||||
shortcut: kav
|
shortcut: kav
|
||||||
|
inactive: true
|
||||||
|
|
||||||
- name: karmasearch news
|
- name: karmasearch news
|
||||||
engine: karmasearch
|
engine: karmasearch
|
||||||
categories: [news, web]
|
categories: [news, web]
|
||||||
search_type: news
|
search_type: news
|
||||||
shortcut: kan
|
shortcut: kan
|
||||||
|
inactive: true
|
||||||
|
|
||||||
- name: kickass
|
- name: kickass
|
||||||
engine: kickass
|
engine: kickass
|
||||||
@@ -2149,6 +2148,7 @@ engines:
|
|||||||
- name: yahoo news
|
- name: yahoo news
|
||||||
engine: yahoo_news
|
engine: yahoo_news
|
||||||
shortcut: yhn
|
shortcut: yhn
|
||||||
|
inactive: true
|
||||||
|
|
||||||
- name: youtube
|
- name: youtube
|
||||||
shortcut: yt
|
shortcut: yt
|
||||||
|
|||||||
Reference in New Issue
Block a user