DOC mention gotcha with `foo::text` selector and empty `foo` elements

also, move "Selecting attributes" reference closer to `a::atr(href)` example
This commit is contained in:
Mikhail Korobov 2018-09-18 05:03:35 +05:00
parent 2c3b2158c9
commit ffbd33edac
1 changed files with 16 additions and 4 deletions

View File

@ -279,6 +279,19 @@ Examples:
'Name: My image 5 ',
'\n ']
* ``foo::text`` returns no results if ``foo`` element exists, but contains
no text (i.e. text is empty)::
>>> response.css('img::text').getall()
[]
This means ``.css('foo::text').get()`` could return None even if an element
exists. Use ``default=''`` if you always want a string::
>>> response.css('img::text').get()
>>> response.css('img::text').get(default='')
''
* ``a::attr(href)`` selects the *href* attribute value of descendant links::
>>> response.css('a::attr(href)').getall()
@ -288,15 +301,14 @@ Examples:
'image4.html',
'image5.html']
.. note::
See also: :ref:`selecting-attributes`.
.. note::
You cannot chain these pseudo-elements. But in practice it would not
make much sense: text nodes do not have attributes, and attribute values
are string values already and do not have children nodes.
.. note::
See also: :ref:`selecting-attributes`.
.. _CSS Selectors: https://www.w3.org/TR/css3-selectors/#selectors
.. _topics-selectors-nesting-selectors: