From 0b9b0976b5219233bee143c09a3f35fc2a44d20e Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 25 Jun 2015 20:53:13 -0400 Subject: You can now create a NavigableString or a subclass just by invoking the constructor. [bug=1294315] --- doc/source/index.rst | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'doc/source/index.rst') diff --git a/doc/source/index.rst b/doc/source/index.rst index bab20d8..3e4d547 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1803,17 +1803,17 @@ like calling ``.append()`` on a Python list:: soup.a.contents # [u'Foo', u'Bar'] -``BeautifulSoup.new_string()`` and ``.new_tag()`` +``NavigableString()`` and ``.new_tag()`` ------------------------------------------------- If you need to add a string to a document, no problem--you can pass a -Python string in to ``append()``, or you can call the factory method -``BeautifulSoup.new_string()``:: +Python string in to ``append()``, or you can call the ``NavigableString`` +constructor:: soup = BeautifulSoup("") tag = soup.b tag.append("Hello") - new_string = soup.new_string(" there") + new_string = NavigableString(" there") tag.append(new_string) tag # Hello there. @@ -1821,18 +1821,17 @@ Python string in to ``append()``, or you can call the factory method # [u'Hello', u' there'] If you want to create a comment or some other subclass of -``NavigableString``, pass that class as the second argument to -``new_string()``:: +``NavigableString``, just call the constructor:: from bs4 import Comment - new_comment = soup.new_string("Nice to see you.", Comment) + new_comment = Comment("Nice to see you.") tag.append(new_comment) tag # Hello there tag.contents # [u'Hello', u' there', u'Nice to see you.'] -(This is a new feature in Beautiful Soup 4.2.1.) +(This is a new feature in Beautiful Soup 4.4.0.) What if you need to create a whole new tag? The best solution is to call the factory method ``BeautifulSoup.new_tag()``:: -- cgit v1.2.3