From 9fb5adba376394f414b7b2301be50f9ca644eef1 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 26 Feb 2018 10:23:08 -0500 Subject: [PATCH] refactor Signed-off-by: Kenneth Reitz --- requests_html.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/requests_html.py b/requests_html.py index d752423..43ca3ff 100644 --- a/requests_html.py +++ b/requests_html.py @@ -199,27 +199,18 @@ class Element(BaseParser): class HTML(BaseParser): """An HTML document.""" - def __init__(self, *, response): + def __init__(self, *, url, html, default_encoding=DEFAULT_ENCODING): super(HTML, self).__init__( - element=fromstring(response.text), - html=response.text, - url=response.url, - default_encoding=response.encoding + element=fromstring(html), + html=html, + url=url, + default_encoding=default_encoding ) def __repr__(self): return "".format(repr(self.url)) -def _handle_response(response, **kwargs): - """Requests HTTP Response handler. Attaches .html property to Response - objects. - """ - - response.html = HTML(response=response) - return response - - def user_agent(style=None): """Returns a random user-agent, if not requested one of a specific style. @@ -253,7 +244,7 @@ class Session(requests.Session): if not response.encoding: response.encoding = DEFAULT_ENCODING - response.html = HTML(response=response) + response.html = HTML(url=response.url, html=response.text, default_encoding=response.encoding) return response