File: traversing.txt

package info (click to toggle)
pyquery 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 308 kB
  • sloc: python: 1,428; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 768 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Traversing
----------

Some jQuery traversal methods are supported.  Here are a few examples.

You can filter the selection list using a string selector::

    >>> d = pq('<p id="hello" class="hello"><a/></p><p id="test"><a/></p>')
    >>> d('p').filter('.hello')
    [<p#hello.hello>]

It is possible to select a single element with eq::

    >>> d('p').eq(0)
    [<p#hello.hello>]

You can find nested elements::

    >>> d('p').find('a')
    [<a>, <a>]
    >>> d('p').eq(1).find('a')
    [<a>]

Breaking out of a level of traversal is also supported using end::

    >>> d('p').find('a').end()
    [<p#hello.hello>, <p#test>]
    >>> d('p').eq(0).end()
    [<p#hello.hello>, <p#test>]
    >>> d('p').filter(lambda i: i == 1).end()
    [<p#hello.hello>, <p#test>]