From 74ca8e3f33d44475401be0bc418da83264f91207 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Fri, 2 Mar 2012 10:29:08 -0500 Subject: Brought the soupselect port up to date. --- doc/source/index.rst | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'doc/source/index.rst') diff --git a/doc/source/index.rst b/doc/source/index.rst index a9d404a..37d5f07 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1538,15 +1538,27 @@ You can find tags:: Find tags beneath other tags:: - soup.select("p a") - # [Elsie, Lacie, Tillie] + soup.select("body a") + # [Elsie, + # Lacie, + # Tillie] soup.select("html head title") # [The Dormouse's story] +Find tags `directly` beneath other tags:: + + soup.select("head > title") + # [The Dormouse's story] + + soup.select("p > a") + # [Elsie, + # Lacie, + # Tillie] + + soup.select("body > a") + # [] + Find tags by CSS class:: soup.select(".sister") @@ -1590,6 +1602,20 @@ Find tags by attribute value:: soup.select('a[href*=".com/el"]') # [Elsie] +Match language codes:: + + multilingual_markup = """ +

Hello

+

Howdy, y'all

+

Pip-pip, old fruit

+

Bonjour mes amis

+ """ + multilingual_soup = BeautifulSoup(multilingual_markup) + multilingual_soup.select('p[lang|=en]') + # [

Hello

, + #

Howdy, y'all

, + #

Pip-pip, old fruit

] + This is a convenience for users who know the CSS selector syntax. You can do all this stuff with the Beautiful Soup API. And if CSS selectors are all you need, you might as well use lxml directly, -- cgit v1.2.3