mirror of
https://github.com/searxng/searxng.git
synced 2026-09-23 06:36:12 +00:00
[feat] SXNG_Response: add method to parse html body (#6718)
This commit is contained in:
@@ -29,6 +29,7 @@ from urllib.parse import urlsplit
|
|||||||
|
|
||||||
import flask
|
import flask
|
||||||
from curl_cffi.requests import Response as CurlResponse
|
from curl_cffi.requests import Response as CurlResponse
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
import searx.preferences
|
import searx.preferences
|
||||||
@@ -100,9 +101,14 @@ class SXNG_Response(CurlResponse):
|
|||||||
_url: str = ""
|
_url: str = ""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self) -> SXNG_URL: # type: ignore[override]
|
def url(self) -> SXNG_URL:
|
||||||
return SXNG_URL(self._url)
|
return SXNG_URL(self._url)
|
||||||
|
|
||||||
@url.setter
|
@url.setter
|
||||||
def url(self, value: str) -> None:
|
def url(self, value: str) -> None:
|
||||||
self._url = str(value or "")
|
self._url = str(value or "")
|
||||||
|
|
||||||
|
def html(self) -> html.HtmlElement:
|
||||||
|
"""Parses the result into a HTML document via :py:obj:`lxml.html`."""
|
||||||
|
|
||||||
|
return html.fromstring(self.text)
|
||||||
|
|||||||
Reference in New Issue
Block a user