Skip to content

Commit 419af4b

Browse files
authored
Merge pull request #248 from shahidkarimi/selector-text-doc
Selector text doc
2 parents f8f1c66 + c6580cc commit 419af4b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/usage.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ pseudo-elements::
120120
>>> selector.css('title::text').get()
121121
'Example website'
122122

123+
To extract all text of one or more element and all their child elements,
124+
formatted as plain text taking into account HTML tags (e.g. ``<br/>`` is
125+
translated as a line break), set ``text=True`` in your call to
126+
:meth:`~Selector.get` or :meth:`~Selector.getall` instead of including
127+
``::text`` (CSS) or ``/text()`` (XPath) in your query:
128+
129+
>>> selector.css('#images').get(text=True)
130+
'Name: My image 1\nName: My image 2\nName: My image 3\nName: My image 4\nName: My image 5'
131+
132+
See :meth:`Selector.get` for additional parameters that you can use to change
133+
how the extracted plain text is formatted.
134+
123135
As you can see, ``.xpath()`` and ``.css()`` methods return a
124136
:class:`~parsel.selector.SelectorList` instance, which is a list of new
125137
selectors. This API can be used for quickly selecting nested data::

0 commit comments

Comments
 (0)