Package rosdeb :: Module BeautifulSoup :: Class Tag
[frames] | no frames]

Class Tag

source code

PageElement --+
              |
             Tag
Known Subclasses:

Represents a found HTML tag with its attributes and contents.

Instance Methods
 
__init__(self, parser, name, attrs=None, parent=None, previous=None)
Basic constructor.
source code
 
get(self, key, default=None)
Returns the value of the 'key' attribute for the tag, or the value given for 'default' if it doesn't have that attribute.
source code
 
has_key(self, key) source code
 
__getitem__(self, key)
tag[key] returns the value of the 'key' attribute for the tag, and throws an exception if it's not there.
source code
 
__iter__(self)
Iterating over a tag iterates over its contents.
source code
 
__len__(self)
The length of a tag is the length of its list of contents.
source code
 
__contains__(self, x) source code
 
__nonzero__(self)
A tag is non-None even if it has no contents.
source code
 
__setitem__(self, key, value)
Setting tag[key] sets the value of the 'key' attribute for the tag.
source code
 
__delitem__(self, key)
Deleting tag[key] deletes all 'key' attributes for the tag.
source code
 
__call__(self, *args, **kwargs)
Calling a tag like a function is the same as calling its findAll() method.
source code
 
__getattr__(self, tag) source code
 
__eq__(self, other)
Returns true iff this tag has the same name, the same attributes, and the same contents (recursively) as the given tag.
source code
 
__ne__(self, other)
Returns true iff this tag is not identical to the other tag, as defined in __eq__.
source code
 
__repr__(self, encoding='utf-8')
Renders this tag as a string.
source code
 
__unicode__(self) source code
 
__str__(self) source code
 
encode(self, encoding='utf-8', prettyPrint=False, indentLevel=0) source code
 
decode(self, prettyPrint=False, indentLevel=0, eventualEncoding='utf-8')
Returns a string or Unicode representation of this tag and its contents.
source code
 
decompose(self)
Recursively destroys the contents of this tree.
source code
 
prettify(self, encoding='utf-8') source code
 
encodeContents(self, encoding='utf-8', prettyPrint=False, indentLevel=0) source code
 
decodeContents(self, prettyPrint=False, indentLevel=0, eventualEncoding='utf-8')
Renders the contents of this tag as a string in the given encoding.
source code
 
find(self, name=None, attrs={}, recursive=True, text=None, **kwargs)
Return only the first child of this Tag matching the given criteria.
source code
 
findChild(self, name=None, attrs={}, recursive=True, text=None, **kwargs)
Return only the first child of this Tag matching the given criteria.
source code
 
findAll(self, name=None, attrs={}, recursive=True, text=None, limit=None, **kwargs)
Extracts a list of Tag objects that match the given criteria.
source code
 
findChildren(self, name=None, attrs={}, recursive=True, text=None, limit=None, **kwargs)
Extracts a list of Tag objects that match the given criteria.
source code
 
first(self, name=None, attrs={}, recursive=True, text=None, **kwargs)
Return only the first child of this Tag matching the given criteria.
source code
 
fetch(self, name=None, attrs={}, recursive=True, text=None, limit=None, **kwargs)
Extracts a list of Tag objects that match the given criteria.
source code
 
fetchText(self, text=None, recursive=True, limit=None) source code
 
firstText(self, text=None, recursive=True) source code
 
renderContents(self, encoding='utf-8', prettyPrint=False, indentLevel=0) source code
 
recursiveChildGenerator(self) source code
 
childGenerator(self) source code
 
append(self, tag)
Appends the given tag to the contents of this tag. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
extract(self)
Destructively rips this element out of the tree. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
fetchNextSiblings(self, name=None, attrs={}, text=None, limit=None, **kwargs)
Returns the siblings of this Tag that match the given criteria and appear after this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
fetchParents(self, name=None, attrs={}, limit=None, **kwargs)
Returns the parents of this Tag that match the given criteria. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
fetchPrevious(self, name=None, attrs={}, text=None, limit=None, **kwargs)
Returns all items that match the given criteria and appear before this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
fetchPreviousSiblings(self, name=None, attrs={}, text=None, limit=None, **kwargs)
Returns the siblings of this Tag that match the given criteria and appear before this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findAllNext(self, name=None, attrs={}, text=None, limit=None, **kwargs)
Returns all items that match the given criteria and appear after this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findAllPrevious(self, name=None, attrs={}, text=None, limit=None, **kwargs)
Returns all items that match the given criteria and appear before this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findNext(self, name=None, attrs={}, text=None, **kwargs)
Returns the first item that matches the given criteria and appears after this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findNextSibling(self, name=None, attrs={}, text=None, **kwargs)
Returns the closest sibling to this Tag that matches the given criteria and appears after this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findNextSiblings(self, name=None, attrs={}, text=None, limit=None, **kwargs)
Returns the siblings of this Tag that match the given criteria and appear after this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findParent(self, name=None, attrs={}, **kwargs)
Returns the closest parent of this Tag that matches the given criteria. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findParents(self, name=None, attrs={}, limit=None, **kwargs)
Returns the parents of this Tag that match the given criteria. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findPrevious(self, name=None, attrs={}, text=None, **kwargs)
Returns the first item that matches the given criteria and appears before this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findPreviousSibling(self, name=None, attrs={}, text=None, **kwargs)
Returns the closest sibling to this Tag that matches the given criteria and appears before this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
findPreviousSiblings(self, name=None, attrs={}, text=None, limit=None, **kwargs)
Returns the siblings of this Tag that match the given criteria and appear before this Tag in the document. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
insert(self, position, newChild) (Inherited from rosdeb.BeautifulSoup.PageElement) source code
 
nextGenerator(self) (Inherited from rosdeb.BeautifulSoup.PageElement) source code
 
nextSiblingGenerator(self) (Inherited from rosdeb.BeautifulSoup.PageElement) source code
 
parentGenerator(self) (Inherited from rosdeb.BeautifulSoup.PageElement) source code
 
previousGenerator(self) (Inherited from rosdeb.BeautifulSoup.PageElement) source code
 
previousSiblingGenerator(self) (Inherited from rosdeb.BeautifulSoup.PageElement) source code
 
replaceWith(self, replaceWith) (Inherited from rosdeb.BeautifulSoup.PageElement) source code
 
setup(self, parent=None, previous=None)
Sets up the initial relations between this element and other elements. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
 
substituteEncoding(self, str, encoding=None) (Inherited from rosdeb.BeautifulSoup.PageElement) source code
 
toEncoding(self, s, encoding=None)
Encodes an object to a string in some encoding, or to Unicode. (Inherited from rosdeb.BeautifulSoup.PageElement)
source code
Class Variables
  XML_ENTITIES_TO_SPECIAL_CHARS = {'amp': '&', 'apos': '\'', 'gt...
  XML_SPECIAL_CHARS_TO_ENTITIES = {'"': 'quot', '&': 'amp', '\''...
  BARE_AMPERSAND_OR_BRACKET = re.compile(r'([<>]|&(?!#\d+;|#x[0-...
Method Details

__call__(self, *args, **kwargs)
(Call operator)

source code 

Calling a tag like a function is the same as calling its findAll() method. Eg. tag('a') returns a list of all the A tags found within this tag.

__eq__(self, other)
(Equality operator)

source code 

Returns true iff this tag has the same name, the same attributes, and the same contents (recursively) as the given tag.

NOTE: right now this will return false if two tags have the same attributes in a different order. Should this be fixed?

decode(self, prettyPrint=False, indentLevel=0, eventualEncoding='utf-8')

source code 

Returns a string or Unicode representation of this tag and its contents. To get Unicode, pass None for encoding.

decodeContents(self, prettyPrint=False, indentLevel=0, eventualEncoding='utf-8')

source code 

Renders the contents of this tag as a string in the given encoding. If encoding is None, returns a Unicode string..

findAll(self, name=None, attrs={}, recursive=True, text=None, limit=None, **kwargs)

source code 

Extracts a list of Tag objects that match the given criteria. You can specify the name of the Tag and any attributes you want the Tag to have.

The value of a key-value pair in the 'attrs' map can be a string, a list of strings, a regular expression object, or a callable that takes a string and returns whether or not the string matches for some custom definition of 'matches'. The same is true of the tag name.

findChildren(self, name=None, attrs={}, recursive=True, text=None, limit=None, **kwargs)

source code 

Extracts a list of Tag objects that match the given criteria. You can specify the name of the Tag and any attributes you want the Tag to have.

The value of a key-value pair in the 'attrs' map can be a string, a list of strings, a regular expression object, or a callable that takes a string and returns whether or not the string matches for some custom definition of 'matches'. The same is true of the tag name.

fetch(self, name=None, attrs={}, recursive=True, text=None, limit=None, **kwargs)

source code 

Extracts a list of Tag objects that match the given criteria. You can specify the name of the Tag and any attributes you want the Tag to have.

The value of a key-value pair in the 'attrs' map can be a string, a list of strings, a regular expression object, or a callable that takes a string and returns whether or not the string matches for some custom definition of 'matches'. The same is true of the tag name.


Class Variable Details

XML_ENTITIES_TO_SPECIAL_CHARS

Value:
{'amp': '&', 'apos': '\'', 'gt': '>', 'lt': '<', 'quot': '"'}

XML_SPECIAL_CHARS_TO_ENTITIES

Value:
{'"': 'quot', '&': 'amp', '\'': 'apos', '<': 'lt', '>': 'gt'}

BARE_AMPERSAND_OR_BRACKET

Value:
re.compile(r'([<>]|&(?!#\d+;|#x[0-9a-fA-F]+;|\w+;))')