✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ beluga.o2switch.net ​🇻​♯➤ 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP 🇾​♯➤ 2026

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 185.154.139.77 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.216.254
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ 𝗔𝗟𝗟 𝗪𝗢𝗥𝗞𝗜𝗡𝗚....

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /opt/alt/python27/share/doc/alt-python27-lxml-docs//cssselect.txt
==============
lxml.cssselect
==============

lxml supports a number of interesting languages for tree traversal and element
selection.  The most important is obviously XPath_, but there is also
ObjectPath_ in the `lxml.objectify`_ module.  The newest child of this family
is `CSS selection`_, which is made available in form of the ``lxml.cssselect``
module.

Although it started its life in lxml, cssselect_ is now an independent project.
It translates CSS selectors to XPath 1.0 expressions that can be used with
lxml's XPath engine.  ``lxml.cssselect`` adds a few convenience shortcuts into
that package.


.. _XPath: xpathxslt.html#xpath
.. _ObjectPath: objectify.html#objectpath
.. _`lxml.objectify`: objectify.html
.. _`CSS selection`: http://www.w3.org/TR/CSS21/selector.html
.. _cssselect: http://packages.python.org/cssselect/

.. contents::
..
   1  The CSSSelector class
   2  CSS Selectors
     2.1  Namespaces
   3  Limitations


The CSSSelector class
=====================

The most important class in the ``lxml.cssselect`` module is ``CSSSelector``.  It
provides the same interface as the XPath_ class, but accepts a CSS selector
expression as input:

.. sourcecode:: pycon

    >>> from lxml.cssselect import CSSSelector
    >>> sel = CSSSelector('div.content')
    >>> sel  #doctest: +ELLIPSIS
    <CSSSelector ... for 'div.content'>
    >>> sel.css
    'div.content'

The selector actually compiles to XPath, and you can see the
expression by inspecting the object:

.. sourcecode:: pycon

    >>> sel.path
    "descendant-or-self::div[@class and contains(concat(' ', normalize-space(@class), ' '), ' content ')]"

To use the selector, simply call it with a document or element
object:

.. sourcecode:: pycon

    >>> from lxml.etree import fromstring
    >>> h = fromstring('''<div id="outer">
    ...   <div id="inner" class="content body">
    ...       text
    ...   </div></div>''')
    >>> [e.get('id') for e in sel(h)]
    ['inner']

Using ``CSSSelector`` is equivalent to translating with ``cssselect``
and using the ``XPath`` class:

.. sourcecode:: pycon

    >>> from cssselect import GenericTranslator
    >>> from lxml.etree import XPath
    >>> sel = XPath(GenericTranslator().css_to_xpath('div.content'))

``CSSSelector`` takes a ``translator`` parameter to let you choose which
translator to use. It can be ``'xml'`` (the default), ``'xhtml'``, ``'html'``
or a `Translator object`_.

.. _Translator object: http://packages.python.org/cssselect/#cssselect.GenericTranslator


The cssselect method
====================

lxml ``Element`` objects have a ``cssselect`` convenience method.

.. sourcecode:: pycon

    >>> h.cssselect('div.content') == sel(h)
    True

Note however that pre-compiling the expression with the ``CSSSelector`` or
``XPath`` class can provide a substantial speedup.

The method also accepts a ``translator`` parameter. On ``HtmlElement``
objects, the default is changed to ``'html'``.


Supported Selectors
===================

Most `Level 3`_ selectors are supported. The details are in the
`cssselect documentation`_.

.. _Level 3: http://www.w3.org/TR/2011/REC-css3-selectors-20110929/
.. _cssselect documentation: http://packages.python.org/cssselect/#supported-selectors


Namespaces
==========

In CSS you can use ``namespace-prefix|element``, similar to
``namespace-prefix:element`` in an XPath expression.  In fact, it maps
one-to-one, and the same rules are used to map namespace prefixes to
namespace URIs: the ``CSSSelector`` class accepts a dictionary as its
``namespaces`` argument.


Current_dir [ 𝗡𝗢𝗧 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
25 Jul 2024 8.45 AM
root / root
0755
html
--
25 Jul 2024 8.45 AM
root / linksafe
0755
licenses
--
25 Jul 2024 8.45 AM
root / linksafe
0755
s5
--
25 Jul 2024 8.45 AM
root / linksafe
0755
FAQ.txt
49.204 KB
12 Apr 2013 5.14 AM
root / linksafe
0644
api.txt
18.848 KB
10 Feb 2013 3.49 PM
root / linksafe
0644
build.txt
11.317 KB
27 Sep 2013 7.39 PM
root / linksafe
0644
capi.txt
2.848 KB
28 Sep 2012 7.13 PM
root / linksafe
0644
compatibility.txt
8.755 KB
28 Sep 2012 7.13 PM
root / linksafe
0644
cssselect.txt
3.473 KB
7 Oct 2012 6.04 PM
root / linksafe
0644
docstructure.py
1.081 KB
21 Dec 2012 10.02 PM
root / linksafe
0644
element_classes.txt
18.866 KB
28 Sep 2012 7.13 PM
root / linksafe
0644
elementsoup.txt
6.53 KB
21 Dec 2012 10.02 PM
root / linksafe
0644
extensions.txt
19.215 KB
11 May 2013 9.26 PM
root / linksafe
0644
html5parser.txt
3.296 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
intro.txt
2.015 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
lxml-source-howto.txt
10.7 KB
28 Sep 2012 7.13 PM
root / linksafe
0644
lxml.mgp
2.188 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
lxml2.txt
10.722 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
lxmlhtml.txt
25.225 KB
28 Apr 2013 6.42 PM
root / linksafe
0644
main.txt
9.856 KB
7 Nov 2013 4.34 PM
root / linksafe
0644
memorymanagement.txt
3.197 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
mkhtml.py
10.13 KB
21 Dec 2012 10.02 PM
root / linksafe
0644
mklatex.py
10.625 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
objectify.txt
43.229 KB
7 Oct 2012 6.04 PM
root / linksafe
0644
parsing.txt
25.333 KB
6 Nov 2013 7.37 PM
root / linksafe
0644
performance.txt
36.574 KB
12 Apr 2013 5.14 AM
root / linksafe
0644
pubkey.asc
2.031 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
resolvers.txt
10.003 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
rest2html.py
1.772 KB
25 Sep 2011 4.58 PM
root / linksafe
0755
rest2latex.py
1.806 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
sax.txt
3.771 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
test.xml
0.005 KB
25 Sep 2011 4.58 PM
root / linksafe
0644
tutorial.txt
43.192 KB
12 Apr 2013 5.14 AM
root / linksafe
0644
valgrind.txt
0.144 KB
28 Sep 2012 7.13 PM
root / linksafe
0644
validation.txt
20.229 KB
7 Oct 2012 6.04 PM
root / linksafe
0644
xpathxslt.txt
22.489 KB
28 Sep 2012 7.13 PM
root / linksafe
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF