Skip to content

Latest commit

 

History

History
100 lines (85 loc) · 3.21 KB

README.md

File metadata and controls

100 lines (85 loc) · 3.21 KB

Python >= 3.8 Downloads Downloads

searxng_search

Web search using the searxng instances.

Table of Contents


Install

pip install -U searxng_search

SearxngSearch class

"""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)

Proxy

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

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.

search()

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)