Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add encoding args to render method #18

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading