Web search using the searxng instances.
pip install -U searxng_search
"""Searxng search. Query params: https://docs.searxng.org/dev/search_api.html.
Args:
q: search query.
language: code of the language. Defaults to "auto".
pageno: search page number. Defaults to 1.
time_range: "day", "week", "month", "year". Defaults to "".
safesearch: 0, 1, 2. Defaults to 1.
"""
Here is an example of initializing the SeaxngSearch class.
from searxng_search import SearxngSearch
results = SearxngSearch().search("python")
print(results)
Package supports http/https/socks proxies. Example: http://user:[email protected]:3128
.
Use a rotating proxy. Otherwise, use a new proxy with each SearxngSearch class initialization.
1. The easiest way. Launch the Tor Browser
from searxng_search import SearxngSearch
ss = SearxngSearch(proxy="socks5://127.0.0.1:9150", timeout=20)
results = SS.search("python")
2. Use any proxy server (example with iproyal rotating residential proxies)
from searxng_search import SearxngSearch
ss = SearxngSearch(proxy="socks5h://user:[email protected]:32325", timeout=20)
results = ss.text("something you need")
3. The proxy can also be set using the SEARXNG_PROXY
environment variable.
export SEARXNG_PROXY="socks5h://user:[email protected]:32325"
Exceptions:
SearxngSearchException
: Base exception for searxng_search errors.RatelimitException
: Inherits from SearxngSearchException, raised for exceeding request rate limits.TimeoutException
: Inherits from SearxngSearchException, raised for request timeouts.
def search(
self,
q: str,
language: str = "auto",
pageno: str | int = 1,
time_range: str = "",
safesearch: str | int = 1,
) -> list[dict[str, str]]:
"""Searxng search. Query params: https://docs.searxng.org/dev/search_api.html.
Args:
q: search query.
language: code of the language. Defaults to "auto".
pageno: search page number. Defaults to 1.
time_range: "day", "week", "month", "year". Defaults to "".
safesearch: 0, 1, 2. Defaults to 1.
Returns:
List of dictionaries with search results.
Example
from searxng_search import SS # SS = SearxngSearch (alias)
results = SS().search("python", language="fr", pageno=4, time_range="year", safesearch=0)
print(results)