CMS 3D CMS Logo

Classes | Functions | Variables

BeautifulSoup Namespace Reference

Classes

class  BeautifulSOAP
class  BeautifulSoup
class  BeautifulStoneSoup
class  CData
class  Comment
class  Declaration
class  HTMLParserBuilder
class  ICantBelieveItsBeautifulSoup
class  MinimalSoup
class  NavigableString
class  PageElement
class  ProcessingInstruction
class  ResultSet
class  RobustHTMLParser
class  RobustInsanelyWackAssHTMLParser
class  RobustWackAssHTMLParser
class  RobustXMLParser
class  SimplifyingSOAPParser
class  SoupStrainer
class  StopParsing
class  Tag
class  UnicodeDammit

Functions

def buildTagMap
def isList
def isString
def sob

Variables

string __author__ = "Leonard Richardson (leonardr@segfault.org)"
string __copyright__ = "Copyright (c) 2004-2009 Leonard Richardson"
string __license__ = "New-style BSD"
string __version__ = "3.1.0.1"
 chardet = None
string DEFAULT_OUTPUT_ENCODING = "utf-8"
dictionary name2codepoint = {}
tuple soup = BeautifulSoup(sys.stdin)

Detailed Description

Beautiful Soup
Elixir and Tonic
"The Screen-Scraper's Friend"
https://www.crummy.com/software/BeautifulSoup/

Beautiful Soup parses a (possibly invalid) XML or HTML document into a
tree representation. It provides methods and Pythonic idioms that make
it easy to navigate, search, and modify the tree.

A well-formed XML/HTML document yields a well-formed data
structure. An ill-formed XML/HTML document yields a correspondingly
ill-formed data structure. If your document is only locally
well-formed, you can use this library to find and process the
well-formed part of it.

Beautiful Soup works with Python 2.2 and up. It has no external
dependencies, but you'll have more success at converting data to UTF-8
if you also install these three packages:

* chardet, for auto-detecting character encodings
  https://chardet.feedparser.org/
* cjkcodecs and iconv_codec, which add more encodings to the ones supported
  by stock Python.
  https://cjkpython.i18n.org/

Beautiful Soup defines classes for two main parsing strategies:

 * BeautifulStoneSoup, for parsing XML, SGML, or your domain-specific
   language that kind of looks like XML.

 * BeautifulSoup, for parsing run-of-the-mill HTML code, be it valid
   or invalid. This class has web browser-like heuristics for
   obtaining a sensible parse tree in the face of common HTML errors.

Beautiful Soup also defines a class (UnicodeDammit) for autodetecting
the encoding of an HTML or XML document, and converting it to
Unicode. Much of this code is taken from Mark Pilgrim's Universal Feed Parser.

For more than you ever wanted to know about Beautiful Soup, see the
documentation:
https://www.crummy.com/software/BeautifulSoup/documentation.html

Here, have some legalese:

Copyright (c) 2004-2009, Leonard Richardson

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

  * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

  * Neither the name of the the Beautiful Soup Consortium and All
Night Kosher Bakery nor the names of its contributors may be
used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE, DAMMIT.


Function Documentation

def BeautifulSoup::buildTagMap (   default,
  args 
)
Turns a list of maps, lists, or scalars into a single map.
Used to build the SELF_CLOSING_TAGS, NESTABLE_TAGS, and
NESTING_RESET_TAGS maps out of lists and partial maps.

Definition at line 984 of file BeautifulSoup.py.

00985                                :
00986     """Turns a list of maps, lists, or scalars into a single map.
00987     Used to build the SELF_CLOSING_TAGS, NESTABLE_TAGS, and
00988     NESTING_RESET_TAGS maps out of lists and partial maps."""
00989     built = {}
00990     for portion in args:
00991         if hasattr(portion, 'items'):
00992             #It's a map. Merge it.
00993             for k,v in portion.items():
00994                 built[k] = v
00995         elif isList(portion) and not isString(portion):
00996             #It's a list. Map each item to the default.
00997             for k in portion:
00998                 built[k] = default
00999         else:
01000             #It's a scalar. Map it to the default.
01001             built[portion] = default
01002     return built
01003 
01004 # Now, the parser classes.

def BeautifulSoup::isList (   l)
Convenience method that works with all 2.x versions of Python
to determine whether or not something is listlike.

Definition at line 970 of file BeautifulSoup.py.

00971              :
00972     """Convenience method that works with all 2.x versions of Python
00973     to determine whether or not something is listlike."""
00974     return ((hasattr(l, '__iter__') and not isString(l))
00975             or (type(l) in (types.ListType, types.TupleType)))

def BeautifulSoup::isString (   s)
Convenience method that works with all 2.x versions of Python
to determine whether or not something is stringlike.

Definition at line 976 of file BeautifulSoup.py.

00977                :
00978     """Convenience method that works with all 2.x versions of Python
00979     to determine whether or not something is stringlike."""
00980     try:
00981         return isinstance(s, unicode) or isinstance(s, basestring)
00982     except NameError:
00983         return isinstance(s, str)

def BeautifulSoup::sob (   unicode,
  encoding 
)
Returns either the given Unicode string or its encoding.

Definition at line 107 of file BeautifulSoup.py.

00108                           :
00109     """Returns either the given Unicode string or its encoding."""
00110     if encoding is None:
00111         return unicode
00112     else:
00113         return unicode.encode(encoding)


Variable Documentation

string BeautifulSoup::__author__ = "Leonard Richardson (leonardr@segfault.org)"

Definition at line 81 of file BeautifulSoup.py.

string BeautifulSoup::__copyright__ = "Copyright (c) 2004-2009 Leonard Richardson"

Definition at line 83 of file BeautifulSoup.py.

string BeautifulSoup::__license__ = "New-style BSD"

Definition at line 84 of file BeautifulSoup.py.

string BeautifulSoup::__version__ = "3.1.0.1"

Definition at line 82 of file BeautifulSoup.py.

Definition at line 1720 of file BeautifulSoup.py.

Definition at line 103 of file BeautifulSoup.py.

Definition at line 94 of file BeautifulSoup.py.

tuple BeautifulSoup::soup = BeautifulSoup(sys.stdin)

Definition at line 1999 of file BeautifulSoup.py.