Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/simonw/soupselect

CSS selector support for BeautifulSoup.
https://github.com/simonw/soupselect

Last synced: 22 days ago
JSON representation

CSS selector support for BeautifulSoup.

Awesome Lists containing this project

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 and the descendant combinator.

soupselect requires BeautifulSoup v3.0.3 or above; it will not work with v2.x

Example usage:

>>> from BeautifulSoup import BeautifulSoup as Soup
>>> from soupselect import select
>>> import urllib
>>> soup = Soup(urllib.urlopen('http://slashdot.org/'))
>>> select(soup, 'div.title h3')
[


Science: ...

,


Star Trek To ...


... ]

You can also monkey-patch the BeautifulSoup class itself:

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


...