Skip to content

Commit

Permalink
add encoding args (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asugawara authored Mar 8, 2024
1 parent c877b74 commit c3ebca7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions requests_html_playwright/requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@
from concurrent.futures import ThreadPoolExecutor
from concurrent.futures._base import TimeoutError
from functools import partial, wraps
from typing import Any, Dict, List, Optional, Set, Tuple, Union
from typing import Any, Dict, List, Literal, Optional, Set, Tuple, Union
from urllib.parse import urljoin, urlparse, urlunparse

import lxml
Expand Down Expand Up @@ -664,6 664,8 @@ def render(
cookies: Optional[List] = None,
send_cookies_session: bool = False,
render_html: bool = False,
encoding: str = DEFAULT_ENCODING,
errors: Literal["strict", "replace", "ignore"] = "strict",
):
"""Reloads the response in Chromium, and replaces HTML content
with an updated version, with JavaScript executed.
Expand All @@ -673,7 675,6 @@ def render(
:param keep_page: If ``True`` will allow you to interact with the browser page through ``r.html.page``.
:param send_cookies_session: If ``True`` send ``HTMLSession.cookies`` convert.
:param cookies: If not ``empty`` send ``cookies``.
If ``script`` is specified, it will execute the provided JavaScript at
runtime. Example:
Expand Down Expand Up @@ -721,8 722,8 @@ def render(

html = HTML(
url=self.url,
html=content.encode(DEFAULT_ENCODING),
default_encoding=DEFAULT_ENCODING,
html=content.encode(encoding=encoding, errors=errors),
default_encoding=encoding,
session=self.session,
)
for k, v in html.__dict__.items():
Expand All @@ -737,6 738,8 @@ async def arender(
cookies: Optional[List] = None,
send_cookies_session: bool = False,
render_html: bool = False,
encoding: str = DEFAULT_ENCODING,
errors: Literal["strict", "replace", "ignore"] = "strict",
):
"""Async version of render. Takes same parameters."""

Expand All @@ -760,8 763,8 @@ async def arender(

html = HTML(
url=self.url,
html=content.encode(DEFAULT_ENCODING),
default_encoding=DEFAULT_ENCODING,
html=content.encode(encoding=encoding, errors=errors),
default_encoding=encoding,
session=self.session,
)
for k, v in html.__dict__.items():
Expand Down

0 comments on commit c3ebca7

Please sign in to comment.