MCPcopy Create free account
hub / github.com/gawel/pyquery / outer_html

Method outer_html

pyquery/pyquery.py:1131–1155  ·  view source on GitHub ↗

Get the html representation of the first selected element:: >>> d = PyQuery(' toto rocks ') >>> print(d('span')) toto rocks >>> print(d('span').outer_html()) toto

(self, method="html")

Source from the content-addressed store, hash-verified

1129
1130 @with_camel_case_alias
1131 def outer_html(self, method="html"):
1132 """Get the html representation of the first selected element::
1133
1134 >>> d = PyQuery('<div><span class="red">toto</span> rocks</div>')
1135 >>> print(d('span'))
1136 <span class="red">toto</span> rocks
1137 >>> print(d('span').outer_html())
1138 <span class="red">toto</span>
1139 >>> print(d('span').outerHtml())
1140 <span class="red">toto</span>
1141
1142 >>> S = PyQuery('<p>Only <b>me</b> & myself</p>')
1143 >>> print(S('b').outer_html())
1144 <b>me</b>
1145
1146 ..
1147 """
1148
1149 if not self:
1150 return None
1151 e0 = self[0]
1152 if e0.tail:
1153 e0 = deepcopy(e0)
1154 e0.tail = ''
1155 return etree.tostring(e0, encoding=str, method=method)
1156
1157 def text(self, value=no_default, **kwargs):
1158 """Get or set the text representation of sub nodes.

Callers 1

Calls

no outgoing calls

Tested by 1