From f71ba86ec04e2ce0ff5a0e64f4f20becadcc6ddc Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 26 Apr 2012 23:29:32 -0400 Subject: Added a new method, wrap(). --- doc/source/index.rst | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'doc/source/index.rst') diff --git a/doc/source/index.rst b/doc/source/index.rst index ef60c24..0e049d1 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1894,11 +1894,24 @@ and replaces it with the tag or string of your choice:: ``replace_with()`` returns the tag or string that was replaced, so that you can examine it or add it back to another part of the tree. +``wrap()`` +---------- + +``PageElement.wrap()`` wraps an element in the tag you specify. It +returns the new wrapper. (New in Beautiful Soup 4.0.5.) + + soup = BeautifulSoup("

I wish I was bold.

") + soup.p.string.wrap(soup.new_tag("b")) + # I wish I was bold. + + soup.p.wrap(soup.new_tag("div") + #

I wish I was bold.

+ ``unwrap()`` --------------------------- -``Tag.unwrap()`` replaces a tag with whatever's inside -that tag. It's good for stripping out markup:: +``Tag.unwrap()`` is the opposite of ``wrap()``. It replaces a tag with +whatever's inside that tag. It's good for stripping out markup:: markup = 'I linked to example.com' soup = BeautifulSoup(markup) @@ -1911,6 +1924,7 @@ that tag. It's good for stripping out markup:: Like ``replace_with()``, ``unwrap()`` returns the tag that was replaced. + Output ====== -- cgit v1.2.3