| |
- builtins.list(builtins.object)
-
- TagCollection
- builtins.object
-
- AdvancedTag
class AdvancedTag(builtins.object) |
|
AdvancedTag - Represents a Tag. Used with AdvancedHTMLParser to create a DOM-model
Keep tag names lowercase.
Use the getters and setters instead of attributes directly, or you may lose accounting. |
|
Methods defined here:
- __getitem__(self, key)
- __init__(self, tagName, attrList=None, isSelfClosing=False)
- __init__ - Construct
@param tagName - String of tag name. This will be lowercased!
@param attrList - A list of tuples (key, value)
@param isSelfClosing - True if self-closing tag ( <tagName attrs /> ) will be set to False if text or children are added.
- __setattr__(self, name, value)
- __str__(self)
- __str__ - Returns start tag, inner text, and end tag
- addClass(self, className)
- addClass - append a class name if not present
- appendChild(self, child)
- appendChild - Append a child to this element.
@param child <AdvancedTag> - Append a child element to this element
- appendNode = appendChild(self, child)
- appendText(self, text)
- appendText - append some inner text
- getAttribute(self, attrName)
- getAttribute - Gets an attribute on this tag. Be wary using this for classname, maybe use addClass/removeClass. Attribute names are all lowercase.
@return - The attribute value, or None if none exists.
- getChildren(self)
- getChildren - returns child nodes as a searchable TagCollection.
@return - TagCollection of the immediate children to this tag.
- getElementById(self, _id)
- getElementById - Search children of this tag for a tag containing an id
@param _id - String of id
@return - AdvancedTag or None
- getElementsByAttr(self, attrName, attrValue)
- getElementsByAttr - Search children of this tag for tags with an attribute name/value pair
@param attrName - Attribute name (lowercase)
@param attrValue - Attribute value
@return - TagCollection of matching elements
- getElementsByClassName(self, className)
- getElementsByClassName - Search children of this tag for tags containing a given class name
@param className - Class name
@return - TagCollection of matching elements
- getElementsByName(self, name)
- getElementsByName - Search children of this tag for tags with a given name
@param name - name to search
@return - TagCollection of matching elements
- getElementsCustomFilter(self, filterFunc)
- getElementsCustomFilter - Searches children of this tag for those matching a provided user function
@param filterFunc <function> - A function or lambda expression that should return "True" if the passed node matches criteria.
@return - TagCollection of matching results
- getElementsWithAttrValues(self, attrName, attrValues)
- getElementsWithAttrValues - Search children of this tag for tags with an attribute name and one of several values
@param attrName <lowercase str> - Attribute name (lowercase)
@param attrValues set<str> - set of acceptable attribute values
@return - TagCollection of matching elements
- getEndTag(self)
- getEndTag - returns the end tag
@return - String of end tag
- getPeers(self)
- getPeers - Get elements who share a parent with this element
@return - TagCollection of elements
- getPeersByAttr(self, attrName, attrValue)
- getPeersByAttr - Gets peers (elements on same level) which match an attribute/value combination.
@param attrName - Name of attribute
@param attrValue - Value that must match
@return - None if no parent element (error condition), otherwise a TagCollection of peers that matched.
- getPeersByClassName(self, className)
- getPeersByClassName - Gets peers (elements on same level) with a given class name
@param className - classname must contain this name
@return - None if no parent element (error condition), otherwise a TagCollection of peers that matched.
- getPeersByName(self, name)
- getPeersByName - Gets peers (elements on same level) with a given name
@param name - Name to match
@return - None if no parent element (error condition), otherwise a TagCollection of peers that matched.
- getPeersWithAttrValues(self, attrName, attrValues)
- getPeersWithAttrValues - Gets peers (elements on same level) whose attribute given by #attrName
are in the list of possible vaues #attrValues
@param attrName - Name of attribute
@param attrValues - List of possible values which will match
@return - None if no parent element (error condition), otherwise a TagCollection of peers that matched.
- getStartTag(self)
- getStartTag - Returns the start tag
@return - String of start tag with attributes
- getStyle(self, styleName)
- getStyle - Gets the value of a style paramater, part of the "style" attribute
@param styleName - The name of the style
@return - String of the value of the style. '' is no value.
- getStyleDict(self)
- getStyleDict - Gets a dictionary of style attribute/value pairs.
@return - OrderedDict of "style" attribute.
- getTagName(self)
- getTagName - Gets the tag name of this Tag.
@return - str
- getUid(self)
- hasAttribute(self, attrName)
- hasAttribute - Checks for the existance of an attribute. Attribute names are all lowercase.
@param attrName <str> - The attribute name
@return <bool> - True or False if attribute exists by that name
- hasClass(self, className)
- hasClass - Test if this tag has a paticular class name
@param className - A class to search
- insertAfter(self, child, afterChild)
- insertAfter - Inserts a child after @afterChild
child - Child to insert
afterChild - Child to insert after. if None, will be appended
- insertBefore(self, child, beforeChild)
- insertBefore - Inserts a child before @beforeChild
child - Child to insert
beforeChild - Child to insert before. if None, will be appended
- removeAttribute(self, attrName)
- removeAttribute - Removes an attribute, by name.
@param attrName <str> - The attribute name
- removeChild(self, child)
- removeChild - Remove a child, if present.
@param child - The child to remove
@return - The child [with parentNode cleared] if removed, otherwise None.
- removeClass(self, className)
- removeClass - remove a class name if present. Returns the class name if removed, otherwise None.
- removeNode = removeChild(self, child)
- removeText(self, text)
- removeText - Removes some inner text
- setAttribute(self, attrName, attrValue)
- setAttribute - Sets an attribute. Be wary using this for classname, maybe use addClass/removeClass. Attribute names are all lowercase.
@param attrName <str> - The name of the attribute
@param attrValue <str> - The value of the attribute
- setAttributes(self, attributesDict)
- setAttributes - Sets several attributes at once, using a dictionary of attrName : attrValue
@param attributesDict - <str:str> - New attribute names -> values
- setStyle(self, styleName, styleValue)
- setStyle - Sets a style param. Example: "display", "block"
If you need to set many styles on an element, use setStyles instead.
It takes a dictionary of attribute, value pairs and applies it all in one go (faster)
To remove a style, set its value to empty string.
When all styles are removed, the "style" attribute will be nullified.
@param styleName - The name of the style element
@param styleValue - The value of which to assign the style element
@return - String of current value of "style" after change is made.
- setStyles(self, styleUpdatesDict)
- setStyles - Sets one or more style params.
This all happens in one shot, so it is much much faster than calling setStyle for every value.
To remove a style, set its value to empty string.
When all styles are removed, the "style" attribute will be nullified.
@param styleUpdatesDict - Dictionary of attribute : value styles.
@return - String of current value of "style" after change is made.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- childNodes
- childNodes - returns immediate child nodes as a TagCollection
@return - TagCollection of child nodes
- classList
- classList - get the list of class names
- id
- innerHTML
- innerHTML - Returns a string of the inner contents of this tag, including children.
@return - String of inner contents
- name
- nextSibling
- nextSibling - Returns the next sibling. This could be text or an element. use nextSiblingElement to ensure element
- nextSiblingElement
- nextSiblingElement - Returns the next sibling that is an element.
- outerHTML
- outerHTML - Returns start tag, innerHTML, and end tag
@return - String of start tag, innerHTML, and end tag
- parentElement
- parentElement - get the parent element
- peers
- peers - Get elements with same parent as this item
@return - TagCollection of elements
- previousSibling
- previousSibling - Returns the previous sibling. This could be text or an element. use previousSiblingElement to ensure element
- previousSiblingElement
- previousSiblingElement - Returns the previous sibling that is an element.
- value
- value - The "value" attribute of this element
|
class TagCollection(builtins.list) |
|
A collection of AdvancedTags. You may use this like a normal list, or you can use the various getElements* functions within to operate on the results.
Generally, this is the return of all get* functions.
All the get* functions called on a TagCollection search all contained elements and their childrens. If you need to check ONLY the elements in the tag collection, and not their children,
either provide your own list comprehension to do so, or use the "filterCollection" method, which takes an arbitrary function/lambda expression and filters just the immediate tags. |
|
- Method resolution order:
- TagCollection
- builtins.list
- builtins.object
Methods defined here:
- __add__(self, others)
- __init__(self, values=None)
- Create this object.
@param values - Initial values, or None for empty
- __sub__(self, others)
- all(self)
- all - A plain list of these elements
@return - List of these elements
- append(self, tag)
- append - Append an item to this tag collection
@param tag - an AdvancedTag
- filterCollection(self, filterFunc)
- filterCollection - Filters only the immediate objects contained within this Collection against a function, not including any children
@param filterFunc <function> - A function or lambda expression that returns True to have that element match
@return TagCollection of tags that met the given criteria
- getElementById(self, _id)
- getElementById - Gets an element within this collection by id
@param _id - string of "id" attribute
@return - a single tag matching the id, or None if none found
- getElementsByAttr(self, attr, value)
- getElementsByAttr - Get elements within this collection posessing a given attribute/value pair
@param attr - Attribute name (lowercase)
@param value - Matching value
@return - TagCollection of all elements matching name/value
- getElementsByClassName(self, className)
- getElementsByClassName - Get elements within this collection containing a specific class name
@param className - A single class name
@return - TagCollection of unique elements within this collection tagged with a specific class name
- getElementsByName(self, name)
- getElementsByName - Get elements within this collection having a specific name
@param name - String of "name" attribute
@return - TagCollection of unique elements within this collection with given "name"
- getElementsByTagName(self, tagName)
- getElementsByTagName - Gets elements within this collection having a specific tag name
@param tagName - String of tag name
@return - TagCollection of unique elements within this collection with given tag name
- getElementsCustomFilter(self, filterFunc)
- getElementsCustomFilter - Get elements within this collection that match a user-provided function.
@param filterFunc <function> - A function that returns True if the element matches criteria
@return - TagCollection of all elements that matched criteria
- getElementsWithAttrValues(self, attr, values)
- getElementsWithAttrValues - Get elements within this collection possessing an attribute name matching one of several values
@param attr <lowercase str> - Attribute name (lowerase)
@param values set<str> - Set of possible matching values
@return - TagCollection of all elements matching criteria
- remove(self, toRemove)
- remove - Remove an item from this tag collection
@param toRemove - an AdvancedTag
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Methods inherited from builtins.list:
- __contains__(self, key, /)
- Return key in self.
- __delitem__(self, key, /)
- Delete self[key].
- __eq__(self, value, /)
- Return self==value.
- __ge__(self, value, /)
- Return self>=value.
- __getattribute__(self, name, /)
- Return getattr(self, name).
- __getitem__(...)
- x.__getitem__(y) <==> x[y]
- __gt__(self, value, /)
- Return self>value.
- __iadd__(self, value, /)
- Implement self+=value.
- __imul__(self, value, /)
- Implement self*=value.
- __iter__(self, /)
- Implement iter(self).
- __le__(self, value, /)
- Return self<=value.
- __len__(self, /)
- Return len(self).
- __lt__(self, value, /)
- Return self<value.
- __mul__(self, value, /)
- Return self*value.n
- __ne__(self, value, /)
- Return self!=value.
- __new__(*args, **kwargs) from builtins.type
- Create and return a new object. See help(type) for accurate signature.
- __repr__(self, /)
- Return repr(self).
- __reversed__(...)
- L.__reversed__() -- return a reverse iterator over the list
- __rmul__(self, value, /)
- Return self*value.
- __setitem__(self, key, value, /)
- Set self[key] to value.
- __sizeof__(...)
- L.__sizeof__() -- size of L in memory, in bytes
- clear(...)
- L.clear() -> None -- remove all items from L
- copy(...)
- L.copy() -> list -- a shallow copy of L
- count(...)
- L.count(value) -> integer -- return number of occurrences of value
- extend(...)
- L.extend(iterable) -> None -- extend list by appending elements from the iterable
- index(...)
- L.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
- insert(...)
- L.insert(index, object) -- insert object before index
- pop(...)
- L.pop([index]) -> item -- remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
- reverse(...)
- L.reverse() -- reverse *IN PLACE*
- sort(...)
- L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*
Data and other attributes inherited from builtins.list:
- __hash__ = None
| |