summaryrefslogtreecommitdiff
path: root/bs4/element.py
diff options
context:
space:
mode:
Diffstat (limited to 'bs4/element.py')
-rw-r--r--bs4/element.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/bs4/element.py b/bs4/element.py
index bd4c3aa..7935cb1 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -1036,6 +1036,21 @@ class Tag(PageElement):
s.append("\n")
return ''.join(s)
+ def encode_contents(
+ self, indent_level=None, encoding=DEFAULT_OUTPUT_ENCODING,
+ formatter="minimal"):
+ """Renders the contents of this tag as a bytestring."""
+ contents = self.decode_contents(indent_level, encoding, formatter)
+ return contents.encode(encoding)
+
+ # Old method for BS3 compatibility
+ def renderContents(self, encoding=DEFAULT_OUTPUT_ENCODING,
+ prettyPrint=False, indentLevel=0):
+ if not prettyPrint:
+ indentLevel = None
+ return self.encode_contents(
+ indent_level=indentLevel, encoding=encoding)
+
#Soup methods
def find(self, name=None, attrs={}, recursive=True, text=None,