Package CHEM :: Package DB :: Package rdb :: Module BeautifulSoup :: Class Tag
[hide private]
[frames] | no frames]

Class Tag



PageElement --+
              |
             Tag
Known Subclasses:
BeautifulStoneSoup

Represents a found HTML tag with its attributes and contents.

Instance Methods [hide private]
 
__init__(self, parser, name, attrs=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., parent=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., previous=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence...)
Basic constructor.
 
get(self, key, default=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence...)
Returns the value of the 'key' attribute for the tag, or the value given for 'default' if it doesn't have that attribute.
 
has_key(self, key)
 
__getitem__(self, key)
tag[key] returns the value of the 'key' attribute for the tag, and throws an exception if it's not there.
 
__iter__(self)
Iterating over a tag iterates over its contents.
 
__len__(self)
The length of a tag is the length of its list of contents.
 
__contains__(self, x)
 
__nonzero__(self)
A tag is non-None even if it has no contents.
 
__setitem__(self, key, value)
Setting tag[key] sets the value of the 'key' attribute for the tag.
 
__delitem__(self, key)
Deleting tag[key] deletes all 'key' attributes for the tag.
 
__call__(self, *args, **kwargs)
Calling a tag like a function is the same as calling its findAll() method.
 
__getattr__(self, tag)
 
__eq__(self, other)
Returns true iff this tag has the same name, the same attributes, and the same contents (recursively) as the given tag.
 
__ne__(self, other)
Returns true iff this tag is not identical to the other tag, as defined in __eq__.
 
__repr__(self, encoding='utf-8')
Renders this tag as a string.
 
__unicode__(self)
 
__str__(self, encoding='utf-8', prettyPrint=False, indentLevel=0)
Returns a string or Unicode representation of this tag and its contents.
 
prettify(self, encoding='utf-8')
 
renderContents(self, encoding='utf-8', prettyPrint=False, indentLevel=0)
Renders the contents of this tag as a string in the given encoding.
 
find(self, name=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., attrs={}, recursive=True, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., **kwargs)
Return only the first child of this Tag matching the given criteria.
 
findChild(self, name=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., attrs={}, recursive=True, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., **kwargs)
Return only the first child of this Tag matching the given criteria.
 
findAll(self, name=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., attrs={}, recursive=True, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., limit=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., **kwargs)
Extracts a list of Tag objects that match the given criteria.
 
findChildren(self, name=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., attrs={}, recursive=True, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., limit=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., **kwargs)
Extracts a list of Tag objects that match the given criteria.
 
first(self, name=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., attrs={}, recursive=True, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., **kwargs)
Return only the first child of this Tag matching the given criteria.
 
fetch(self, name=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., attrs={}, recursive=True, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., limit=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., **kwargs)
Extracts a list of Tag objects that match the given criteria.
 
fetchText(self, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., recursive=True, limit=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence...)
 
firstText(self, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., recursive=True)
 
append(self, tag)
Appends the given tag to the contents of this tag.
 
_getAttrMap(self)
Initializes a map representation of this tag's attributes, if not already initialized.
 
childGenerator(self)
 
recursiveChildGenerator(self)

Inherited from PageElement: extract, fetchNextSiblings, fetchParents, fetchPrevious, fetchPreviousSiblings, findAllNext, findAllPrevious, findNext, findNextSibling, findNextSiblings, findParent, findParents, findPrevious, findPreviousSibling, findPreviousSiblings, insert, nextGenerator, nextSiblingGenerator, parentGenerator, previousGenerator, previousSiblingGenerator, replaceWith, setup, substituteEncoding, toEncoding

Inherited from PageElement (private): _findAll, _findOne, _lastRecursiveChild

Class Variables [hide private]
  XML_SPECIAL_CHARS_TO_ENTITIES = {'"': 'quote', '&': 'amp', '\'...
Method Details [hide private]

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

 
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)

 

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?

__str__(self, encoding='utf-8', prettyPrint=False, indentLevel=0)
(Informal representation operator)

 

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

NOTE: since Python's HTML parser consumes whitespace, this method is not certain to reproduce the whitespace present in the original string.

renderContents(self, encoding='utf-8', prettyPrint=False, indentLevel=0)

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

findAll(self, name=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., attrs={}, recursive=True, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., limit=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., **kwargs)

 

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=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., attrs={}, recursive=True, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., limit=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., **kwargs)

 

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=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., attrs={}, recursive=True, text=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., limit=<CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSentence..., **kwargs)

 

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 [hide private]

XML_SPECIAL_CHARS_TO_ENTITIES

Value:
{'"': 'quote', '&': 'amp', '\'': 'squot', '<': 'lt', '>': 'gt'}