MCPcopy Create free account
hub / github.com/psf/requests-html / encoding

Method encoding

requests_html.py:119–136  ·  view source on GitHub ↗

The encoding string to be used, extracted from the HTML and :class:`HTMLResponse ` headers.

(self)

Source from the content-addressed store, hash-verified

117
118 @property
119 def encoding(self) -> _Encoding:
120 """The encoding string to be used, extracted from the HTML and
121 :class:`HTMLResponse <HTMLResponse>` headers.
122 """
123 if self._encoding:
124 return self._encoding
125
126 # Scan meta tags for charset.
127 if self._html:
128 self._encoding = html_to_unicode(self.default_encoding, self._html)[0]
129 # Fall back to requests' detected encoding if decode fails.
130 try:
131 self.raw_html.decode(self.encoding, errors='replace')
132 except UnicodeDecodeError:
133 self._encoding = self.default_encoding
134
135
136 return self._encoding if self._encoding else self.default_encoding
137
138 @encoding.setter
139 def encoding(self, enc: str) -> None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected