mirror of https://github.com/searxng/searxng.git
Compare commits
7 Commits
4b38b7f223
...
fcc29987af
Author | SHA1 | Date |
---|---|---|
Ben Curtis | fcc29987af | |
Markus Heiser | 0f9694c90b | |
Markus Heiser | ccc4f30b20 | |
Markus Heiser | c4b874e9b0 | |
Markus Heiser | 7c4e4ebd40 | |
Fmstrat | 5e11d697ab | |
Fmstrat | 8ae66a7eaa |
|
@ -4,22 +4,27 @@ Welcome to SearXNG
|
|||
|
||||
*Search without being tracked.*
|
||||
|
||||
SearXNG is a free internet metasearch engine which aggregates results from more
|
||||
than 70 search services. Users are neither tracked nor profiled. Additionally,
|
||||
SearXNG can be used over Tor for online anonymity.
|
||||
.. jinja:: searx
|
||||
|
||||
SearXNG is a free internet metasearch engine which aggregates results from up
|
||||
to {{engines | length}} :ref:`search services <configured engines>`. Users
|
||||
are neither tracked nor profiled. Additionally, SearXNG can be used over Tor
|
||||
for online anonymity.
|
||||
|
||||
Get started with SearXNG by using one of the instances listed at searx.space_.
|
||||
If you don't trust anyone, you can set up your own, see :ref:`installation`.
|
||||
|
||||
.. jinja:: searx
|
||||
|
||||
.. sidebar:: features
|
||||
|
||||
- :ref:`self hosted <installation>`
|
||||
- :ref:`no user tracking / no profiling <SearXNG protect privacy>`
|
||||
- script & cookies are optional
|
||||
- secure, encrypted connections
|
||||
- :ref:`about 200 search engines <configured engines>`
|
||||
- `about 60 translations <https://translate.codeberg.org/projects/searxng/searxng/>`_
|
||||
- about 100 `well maintained <https://uptime.searxng.org/>`__ instances on searx.space_
|
||||
- :ref:`{{engines | length}} search engines <configured engines>`
|
||||
- `58 translations <https://translate.codeberg.org/projects/searxng/searxng/>`_
|
||||
- about 70 `well maintained <https://uptime.searxng.org/>`__ instances on searx.space_
|
||||
- :ref:`easy integration of search engines <demo online engine>`
|
||||
- professional development: `CI <https://github.com/searxng/searxng/actions>`_,
|
||||
`quality assurance <https://dev.searxng.org/>`_ &
|
||||
|
|
|
@ -320,6 +320,51 @@ def _parse_data_images(dom):
|
|||
return data_image_map
|
||||
|
||||
|
||||
def _eval_answers(results, dom, xpath):
|
||||
answer_list = eval_xpath(dom, xpath)
|
||||
drop_elements = [
|
||||
'.//div[@class="nnFGuf"]',
|
||||
'.//script', # Scripts like the calculator
|
||||
'.//table[@class="HOoTuc"]', # The actual calculator controls
|
||||
'.//table[@class="ElumCf"]', # The actual calculator buttons
|
||||
'.//div[@class="mDRaHd"]', # Instructions with links
|
||||
'.//span[@class="W7GCoc CNbPnc"]', # Feedback
|
||||
'.//*[@style="display:none"]', # Hidden elements
|
||||
]
|
||||
for item in answer_list:
|
||||
for element in eval_xpath(item, ' | '.join(drop_elements)):
|
||||
element.drop_tree()
|
||||
extracted_table_html = None
|
||||
is_safe = False
|
||||
table_elements = eval_xpath(item, './/table')
|
||||
if table_elements:
|
||||
extracted_table = table_elements[0]
|
||||
extracted_table.attrib.clear()
|
||||
for element in extracted_table.xpath('.//*'):
|
||||
element.attrib.clear()
|
||||
extracted_table.set('cellpadding', '2')
|
||||
extracted_table.set('cellspacing', '2')
|
||||
extracted_table.set('border', '0')
|
||||
extracted_table_html = html.tostring(extracted_table, pretty_print=True, encoding='unicode')
|
||||
is_safe = True
|
||||
for element in eval_xpath(item, './/table'): # Drop all remaining tables
|
||||
element.drop_tree()
|
||||
answer_content = extract_text(item)
|
||||
if extracted_table_html:
|
||||
answer_content += '<p>' + extracted_table_html
|
||||
url = (eval_xpath(item, '../..//a/@href') + [None])[0]
|
||||
if url and url.startswith('/search?'): # If the answer is a Google search link, don't use it
|
||||
url = None
|
||||
results.append(
|
||||
{
|
||||
'answer': answer_content,
|
||||
'url': url,
|
||||
'safe': is_safe,
|
||||
}
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def response(resp):
|
||||
"""Get response from google's search request"""
|
||||
# pylint: disable=too-many-branches, too-many-statements
|
||||
|
@ -331,17 +376,21 @@ def response(resp):
|
|||
dom = html.fromstring(resp.text)
|
||||
data_image_map = _parse_data_images(dom)
|
||||
|
||||
# results --> answer
|
||||
answer_list = eval_xpath(dom, '//div[contains(@class, "LGOjhe")]')
|
||||
for item in answer_list:
|
||||
for bubble in eval_xpath(item, './/div[@class="nnFGuf"]'):
|
||||
bubble.drop_tree()
|
||||
results.append(
|
||||
{
|
||||
'answer': extract_text(item),
|
||||
'url': (eval_xpath(item, '../..//a/@href') + [None])[0],
|
||||
}
|
||||
)
|
||||
results = _eval_answers(results, dom, '//div[contains(@class, "card-section")]') # Look for cards first
|
||||
if not results:
|
||||
results = _eval_answers(results, dom, '//div[contains(@class, "LGOjhe")]') # Look for rendered answers next
|
||||
# Look for JS DOM encoded string answers last
|
||||
if not results:
|
||||
pattern = r"'\\x3c.*?\\x3e'" # These are DOM encoded strings that Google will push into the DOM
|
||||
matches = re.findall(pattern, resp.text)
|
||||
for match in matches:
|
||||
decoded_html = match.encode().decode('unicode_escape')
|
||||
encoded_dom = html.fromstring(decoded_html)
|
||||
sub_doms = eval_xpath(encoded_dom, '//div[contains(@class, "LGOjhe")]')
|
||||
if sub_doms:
|
||||
if '<span class="hgKElc"><b>' in decoded_html: # Main answers start with a bold
|
||||
results = _eval_answers(results, encoded_dom, '//div[contains(@class, "LGOjhe")]')
|
||||
break # If it's a JS encoded answer, we only want the first one if it has bold above
|
||||
|
||||
# parse results
|
||||
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Internet Archive scholar(science)
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from urllib.parse import urlencode
|
||||
from searx.utils import html_to_text
|
||||
|
||||
about = {
|
||||
"website": "https://scholar.archive.org/",
|
||||
"wikidata_id": "Q115667709",
|
||||
"official_api_documentation": "https://scholar.archive.org/api/redoc",
|
||||
"use_official_api": True,
|
||||
"require_api_key": False,
|
||||
"results": "JSON",
|
||||
}
|
||||
categories = ['science', 'scientific publications']
|
||||
paging = True
|
||||
|
||||
base_url = "https://scholar.archive.org"
|
||||
results_per_page = 15
|
||||
|
||||
|
||||
def request(query, params):
|
||||
args = {
|
||||
"q": query,
|
||||
"limit": results_per_page,
|
||||
"offset": (params["pageno"] - 1) * results_per_page,
|
||||
}
|
||||
params["url"] = f"{base_url}/search?{urlencode(args)}"
|
||||
params["headers"]["Accept"] = "application/json"
|
||||
return params
|
||||
|
||||
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
json = resp.json()
|
||||
|
||||
for result in json["results"]:
|
||||
publishedDate, content, doi = None, '', None
|
||||
|
||||
if result['biblio'].get('release_date'):
|
||||
publishedDate = datetime.strptime(result['biblio']['release_date'], "%Y-%m-%d")
|
||||
|
||||
if len(result['abstracts']) > 0:
|
||||
content = result['abstracts'][0].get('body')
|
||||
elif len(result['_highlights']) > 0:
|
||||
content = result['_highlights'][0]
|
||||
|
||||
if len(result['releases']) > 0:
|
||||
doi = result['releases'][0].get('doi')
|
||||
|
||||
results.append(
|
||||
{
|
||||
'template': 'paper.html',
|
||||
'url': result['fulltext']['access_url'],
|
||||
'title': result['biblio'].get('title') or result['biblio'].get('container_name'),
|
||||
'content': html_to_text(content),
|
||||
'publisher': result['biblio'].get('publisher'),
|
||||
'doi': doi,
|
||||
'journal': result['biblio'].get('container_name'),
|
||||
'authors': result['biblio'].get('contrib_names'),
|
||||
'tags': result['tags'],
|
||||
'publishedDate': publishedDate,
|
||||
'issns': result['biblio'].get('issns'),
|
||||
'pdf_url': result['fulltext'].get('access_url'),
|
||||
}
|
||||
)
|
||||
|
||||
return results
|
|
@ -27,7 +27,7 @@ categories = ['images']
|
|||
paging = True
|
||||
|
||||
endpoint = 'photos'
|
||||
base_url = 'https://loc.gov'
|
||||
base_url = 'https://www.loc.gov'
|
||||
search_string = "/{endpoint}/?sp={page}&{query}&fo=json"
|
||||
|
||||
|
||||
|
|
|
@ -233,8 +233,7 @@ class Network:
|
|||
del kwargs['raise_for_httperror']
|
||||
return do_raise_for_httperror
|
||||
|
||||
@staticmethod
|
||||
def patch_response(response, do_raise_for_httperror):
|
||||
def patch_response(self, response, do_raise_for_httperror):
|
||||
if isinstance(response, httpx.Response):
|
||||
# requests compatibility (response is not streamed)
|
||||
# see also https://www.python-httpx.org/compatibility/#checking-for-4xx5xx-responses
|
||||
|
@ -242,8 +241,11 @@ class Network:
|
|||
|
||||
# raise an exception
|
||||
if do_raise_for_httperror:
|
||||
try:
|
||||
raise_for_httperror(response)
|
||||
|
||||
except:
|
||||
self._logger.warning(f"HTTP Request failed: {response.request.method} {response.request.url}")
|
||||
raise
|
||||
return response
|
||||
|
||||
def is_valid_response(self, response):
|
||||
|
@ -269,7 +271,7 @@ class Network:
|
|||
else:
|
||||
response = await client.request(method, url, **kwargs)
|
||||
if self.is_valid_response(response) or retries <= 0:
|
||||
return Network.patch_response(response, do_raise_for_httperror)
|
||||
return self.patch_response(response, do_raise_for_httperror)
|
||||
except httpx.RemoteProtocolError as e:
|
||||
if not was_disconnected:
|
||||
# the server has closed the connection:
|
||||
|
|
|
@ -137,9 +137,6 @@ class OnlineProcessor(EngineProcessor):
|
|||
self.engine.request(query, params)
|
||||
|
||||
# ignoring empty urls
|
||||
if params['url'] is None:
|
||||
return None
|
||||
|
||||
if not params['url']:
|
||||
return None
|
||||
|
||||
|
|
|
@ -1622,11 +1622,6 @@ engines:
|
|||
api_site: 'askubuntu'
|
||||
categories: [it, q&a]
|
||||
|
||||
- name: internetarchivescholar
|
||||
engine: internet_archive_scholar
|
||||
shortcut: ias
|
||||
timeout: 15.0
|
||||
|
||||
- name: superuser
|
||||
engine: stackexchange
|
||||
shortcut: su
|
||||
|
|
|
@ -23,7 +23,11 @@
|
|||
<div id="answers" role="complementary" aria-labelledby="answers-title"><h4 class="title" id="answers-title">{{ _('Answers') }} : </h4>
|
||||
{%- for answer in answers.values() -%}
|
||||
<div class="answer">
|
||||
{%- if answer.safe -%}
|
||||
<span>{{ answer.answer | safe }}</span>
|
||||
{%- else -%}
|
||||
<span>{{ answer.answer }}</span>
|
||||
{%- endif -%}
|
||||
{%- if answer.url -%}
|
||||
<a href="{{ answer.url }}" class="answer-url"
|
||||
{%- if results_on_new_tab %} target="_blank" rel="noopener noreferrer"
|
||||
|
|
Loading…
Reference in New Issue