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

Method text

pyquery/pyquery.py:1157–1199  ·  view source on GitHub ↗

Get or set the text representation of sub nodes. Get the text value:: >>> doc = PyQuery(' toto tata ') >>> print(doc.text()) tototata >>> doc = PyQuery(''' toto ...

(self, value=no_default, **kwargs)

Source from the content-addressed store, hash-verified

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.
1159
1160 Get the text value::
1161
1162 >>> doc = PyQuery('<div><span>toto</span><span>tata</span></div>')
1163 >>> print(doc.text())
1164 tototata
1165 >>> doc = PyQuery(''&#x27;<div><span>toto</span>
1166 ... <span>tata</span></div>''&#x27;)
1167 >>> print(doc.text())
1168 toto tata
1169
1170 Get the text value, without squashing newlines::
1171
1172 >>> doc = PyQuery(''&#x27;<div><span>toto</span>
1173 ... <span>tata</span></div>''&#x27;)
1174 >>> print(doc.text(squash_space=False))
1175 toto
1176 tata
1177
1178 Set the text value::
1179
1180 >>> doc.text('Youhou !')
1181 [<div>]
1182 >>> print(doc)
1183 <div>Youhou !</div>
1184
1185 """
1186
1187 if value is no_default:
1188 if not self:
1189 return ''
1190 return ' '.join(
1191 self._copy(tag).html() if tag.tag == 'textarea' else
1192 extract_text(tag, **kwargs) for tag in self
1193 )
1194
1195 for tag in self:
1196 for child in tag.getchildren():
1197 tag.remove(child)
1198 tag.text = value
1199 return self
1200
1201 ################
1202 # Manipulating #

Callers 15

_set_valueMethod · 0.80
test_pseudo_classesMethod · 0.80
test_mapMethod · 0.80
test_open_filenameMethod · 0.80
test_invalid_filenameMethod · 0.80
test_commentMethod · 0.80
test_fn_with_kwargsMethod · 0.80
test_val_for_textareaMethod · 0.80
test_val_for_selectMethod · 0.80
test_selectorMethod · 0.80

Calls 5

_copyMethod · 0.95
extract_textFunction · 0.85
joinMethod · 0.80
htmlMethod · 0.80
removeMethod · 0.80

Tested by 15

test_pseudo_classesMethod · 0.64
test_mapMethod · 0.64
test_open_filenameMethod · 0.64
test_invalid_filenameMethod · 0.64
test_commentMethod · 0.64
test_fn_with_kwargsMethod · 0.64
test_val_for_textareaMethod · 0.64
test_val_for_selectMethod · 0.64
test_selectorMethod · 0.64
test_xhtml_namespaceMethod · 0.64