https://github.com/simonw/soupselect
CSS selector support for BeautifulSoup.
https://github.com/simonw/soupselect
Last synced: 2 months ago
JSON representation
CSS selector support for BeautifulSoup.
- Host: GitHub
- URL: https://github.com/simonw/soupselect
- Owner: simonw
- License: mit
- Created: 2009-05-03T22:47:08.000Z (about 16 years ago)
- Default Branch: master
- Last Pushed: 2020-10-11T15:17:06.000Z (over 4 years ago)
- Last Synced: 2024-10-18T07:54:06.268Z (9 months ago)
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 62
- Watchers: 5
- Forks: 21
- Open Issues: 4
-
Metadata Files:
- Readme: README
- License: LICENSE
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')
[
...