CSS selector support for BeautifulSoup.
Pull request Compare This branch is even with jhg:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
soupselect
README
__init__.py
setup.py
soupselect_tests.py

README

A single function, select(soup, selector), that can be used to select items
from a BeautifulSoup instance using CSS selector syntax.

Currently supports type selectors, class selectors, id selectors, attribute
selectors, the descendant combinator and the immediate child (`>`) combinator.

This branch of soupselect requires BeautifulSoup 4.0 or above; it will not work
with v2.x or v3.x.

Example usage:
    >>> from bs4 import BeautifulSoup as Soup
    >>> from soupselect import select
    >>> import urllib
    >>> soup = Soup(urllib.urlopen('http://slashdot.org/'))
    >>> select(soup, 'div.title h3')
    [<h3>
    <span><a href='//science.slashdot.org/'>Science</a>:</span> ...
    </h3>, <h3>
    <a href='//slashdot.org/articles/07/02/28/0120220.shtml'>Star Trek To ...
    </h3>
    ... ]

You can also monkey-patch the BeautifulSoup class itself:

    >>> from bs4 import BeautifulSoup as Soup
    >>> import soupselect; soupselect.monkeypatch()
    >>> import urllib
    >>> soup = Soup(urllib.urlopen('http://slashdot.org/'))
    >>> soup.findSelect('div.title h3')
    [<h3>
    ...