Skip to content

Commit

Permalink
raw_html
Browse files Browse the repository at this point in the history
Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
  • Loading branch information
kennethreitz committed Feb 27, 2018
1 parent 08a0848 commit ff2f35e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@ def __init__(self, *, element, default_encoding: str = None, html: str = None, u
self._html = html

@property
def html(self) -> str:
"""Unicode representation of the HTML content."""
def raw_html(self):
"""Bytes representation of the HTML content."""
if self._html:
return self._html
else:
return etree.tostring(self.element, encoding='unicode').strip().encode(self.encoding)

@property
def html(self) -> bytes:
"""Unicode representation of the HTML content."""
if self._html:
return self._html.decode(self.encoding)
else:
return etree.tostring(self.element, encoding='unicode').strip()

@html.setter
def set_html(self, html: str) -> None:
def set_html(self, html: bytes) -> None:
"""Property setter for self.html."""
self._html = html

Expand All @@ -57,7 +65,7 @@ def encoding(self) -> str:

# Scan meta tags for chaset.
if self._html:
self._encoding = html_to_unicode(self.default_encoding, self.html.encode(DEFAULT_ENCODING))[0]
self._encoding = html_to_unicode(self.default_encoding, self._html)[0]

return self._encoding if self._encoding else self.default_encoding

Expand Down Expand Up @@ -265,7 +273,7 @@ def html(self) -> HTML:
if self._html:
return self._html

self._html = HTML(url=self.url, html=self.text, default_encoding=self.encoding)
self._html = HTML(url=self.url, html=self.content, default_encoding=self.encoding)
return self._html

@classmethod
Expand Down

0 comments on commit ff2f35e

Please sign in to comment.