mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Merge 7afa72708c
into 3535377c9a
This commit is contained in:
commit
773453c2d3
2 changed files with 47 additions and 6 deletions
|
@ -30,6 +30,13 @@ Configured ``brave`` engines:
|
||||||
...
|
...
|
||||||
brave_category: news
|
brave_category: news
|
||||||
|
|
||||||
|
- name: brave.goggles
|
||||||
|
brave_category: goggles
|
||||||
|
time_range_support: true
|
||||||
|
paging: true
|
||||||
|
...
|
||||||
|
brave_category: goggles
|
||||||
|
|
||||||
|
|
||||||
.. _brave regions:
|
.. _brave regions:
|
||||||
|
|
||||||
|
@ -58,6 +65,23 @@ region are mapped to regions in SearXNG (see :py:obj:`babel
|
||||||
low quality.
|
low quality.
|
||||||
|
|
||||||
|
|
||||||
|
.. _brave googles:
|
||||||
|
|
||||||
|
Brave Goggles
|
||||||
|
=============
|
||||||
|
|
||||||
|
.. _list of Goggles: https://search.brave.com/goggles/discover
|
||||||
|
.. _Goggles Whitepaper: https://brave.com/static-assets/files/goggles.pdf
|
||||||
|
.. _Goggles Quickstart: https://github.com/brave/goggles-quickstart
|
||||||
|
|
||||||
|
Goggles allow you to choose, alter, or extend the ranking of Brave Search
|
||||||
|
results (`Goggles Whitepaper`_). Goggles are openly developed by the community
|
||||||
|
of Brave Search users.
|
||||||
|
|
||||||
|
Select from the `list of Goggles`_ people have published, or create your own
|
||||||
|
(`Goggles Quickstart`_).
|
||||||
|
|
||||||
|
|
||||||
.. _brave languages:
|
.. _brave languages:
|
||||||
|
|
||||||
Brave languages
|
Brave languages
|
||||||
|
@ -95,7 +119,7 @@ Implementations
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from urllib.parse import (
|
from urllib.parse import (
|
||||||
urlencode,
|
urlencode,
|
||||||
|
@ -133,12 +157,14 @@ about = {
|
||||||
base_url = "https://search.brave.com/"
|
base_url = "https://search.brave.com/"
|
||||||
categories = []
|
categories = []
|
||||||
brave_category = 'search'
|
brave_category = 'search'
|
||||||
"""Brave supports common web-search, video search, image and video search.
|
Goggles = Any
|
||||||
|
"""Brave supports common web-search, videos, images, news, and goggles search.
|
||||||
|
|
||||||
- ``search``: Common WEB search
|
- ``search``: Common WEB search
|
||||||
- ``videos``: search for videos
|
- ``videos``: search for videos
|
||||||
- ``images``: search for images
|
- ``images``: search for images
|
||||||
- ``news``: search for news
|
- ``news``: search for news
|
||||||
|
- ``goggles``: Common WEB search with custom rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
brave_spellcheck = False
|
brave_spellcheck = False
|
||||||
|
@ -151,7 +177,7 @@ in SearXNG, the spellchecking is disabled by default.
|
||||||
send_accept_language_header = True
|
send_accept_language_header = True
|
||||||
paging = False
|
paging = False
|
||||||
"""Brave only supports paging in :py:obj:`brave_category` ``search`` (UI
|
"""Brave only supports paging in :py:obj:`brave_category` ``search`` (UI
|
||||||
category All)."""
|
category All) and in the goggles category."""
|
||||||
max_page = 10
|
max_page = 10
|
||||||
"""Tested 9 pages maximum (``&offset=8``), to be save max is set to 10. Trying
|
"""Tested 9 pages maximum (``&offset=8``), to be save max is set to 10. Trying
|
||||||
to do more won't return any result and you will most likely be flagged as a bot.
|
to do more won't return any result and you will most likely be flagged as a bot.
|
||||||
|
@ -183,12 +209,15 @@ def request(query, params):
|
||||||
if brave_spellcheck:
|
if brave_spellcheck:
|
||||||
args['spellcheck'] = '1'
|
args['spellcheck'] = '1'
|
||||||
|
|
||||||
if brave_category == 'search':
|
if brave_category in ('search', 'goggles'):
|
||||||
if params.get('pageno', 1) - 1:
|
if params.get('pageno', 1) - 1:
|
||||||
args['offset'] = params.get('pageno', 1) - 1
|
args['offset'] = params.get('pageno', 1) - 1
|
||||||
if time_range_map.get(params['time_range']):
|
if time_range_map.get(params['time_range']):
|
||||||
args['tf'] = time_range_map.get(params['time_range'])
|
args['tf'] = time_range_map.get(params['time_range'])
|
||||||
|
|
||||||
|
if brave_category == 'goggles':
|
||||||
|
args['goggles_id'] = Goggles
|
||||||
|
|
||||||
params["url"] = f"{base_url}{brave_category}?{urlencode(args)}"
|
params["url"] = f"{base_url}{brave_category}?{urlencode(args)}"
|
||||||
|
|
||||||
# set properties in the cookies
|
# set properties in the cookies
|
||||||
|
@ -209,7 +238,7 @@ def request(query, params):
|
||||||
|
|
||||||
def response(resp):
|
def response(resp):
|
||||||
|
|
||||||
if brave_category == 'search':
|
if brave_category in ('search', 'goggles'):
|
||||||
return _parse_search(resp)
|
return _parse_search(resp)
|
||||||
|
|
||||||
datastr = ""
|
datastr = ""
|
||||||
|
@ -252,7 +281,9 @@ def _parse_search(resp):
|
||||||
if url is None or title_tag is None or not urlparse(url).netloc: # partial url likely means it's an ad
|
if url is None or title_tag is None or not urlparse(url).netloc: # partial url likely means it's an ad
|
||||||
continue
|
continue
|
||||||
|
|
||||||
content_tag = eval_xpath_getindex(result, './/div[@class="snippet-description"]', 0, default='')
|
content_tag = eval_xpath_getindex(
|
||||||
|
result, './/div[@class="snippet-description desktop-default-regular"]', 0, default=''
|
||||||
|
)
|
||||||
img_src = eval_xpath_getindex(result, './/img[contains(@class, "thumb")]/@src', 0, default='')
|
img_src = eval_xpath_getindex(result, './/img[contains(@class, "thumb")]/@src', 0, default='')
|
||||||
|
|
||||||
item = {
|
item = {
|
||||||
|
|
|
@ -2154,6 +2154,16 @@ engines:
|
||||||
categories: news
|
categories: news
|
||||||
brave_category: news
|
brave_category: news
|
||||||
|
|
||||||
|
# - name: brave.goggles
|
||||||
|
# engine: brave
|
||||||
|
# network: brave
|
||||||
|
# shortcut: brgog
|
||||||
|
# time_range_support: true
|
||||||
|
# paging: true
|
||||||
|
# categories: [general, web]
|
||||||
|
# brave_category: goggles
|
||||||
|
# Goggles: # required! This should be a URL ending in .goggle
|
||||||
|
|
||||||
- name: lib.rs
|
- name: lib.rs
|
||||||
shortcut: lrs
|
shortcut: lrs
|
||||||
engine: xpath
|
engine: xpath
|
||||||
|
|
Loading…
Add table
Reference in a new issue