pykhtml.dom
Document object for accessing the DOM tree. Don't keep this object around, when the page changes it is invalidated. Just access it through
pykhtml.Browser.document whenever you want it.
Get a reference to an element in the page by its id attribute.
Get elements in the document that have a certain class.
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().
Get elements by tag name given a certain namespace.
Return a string that represents the DOM structure of this document, much like what is returned via innerHTML in JavaScript.
Visit a page pointed to by a certain link. This function searches for all links in the document that either:
- Match the given text (as a string or regular expression object)
- Match the attributes given (a dictionary mapping attribute name to attribute value, where the value is again either a string or regular expression object)
If the `stripSpace` attribute is True, when searching for a string match all whitespace is stripped from the item we are matching against.
Node and all of its subclasses provide you with access to the page's DOM. Instantiating the classes themselves won't do you much good.
Iterate over child nodes.
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
For those that can't live without JavaScript DOM-compatible method names.
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.
Syntactic sugar for isinstance.
An HTML element. It provides methods for:
And more.
Get the value of the attribute with the given name.
Iterate over child nodes.
Set the value of the attribute with the given name.
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
For those that can't live without JavaScript DOM-compatible method names.
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.
The class name of this element.
Simluate a click on the element. You can optionally specify that a different button was clicked (defaults to "left" – can be "left", "middle", or "right") or that shift/ctrl are held down at the time of click.
Get elements in the document (optionally with a given tag name) that have a certain class.
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().
Get elements by tag name given a certain namespace.
Check whether an attribute exists in this element.
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.
Syntactic sugar for isinstance.
Like tagName but this won't convert things to lower. Only really useful if you're dealing with XML, which probably isn't the case anyway!
Get the lowercase name of this tag.
If the next child of this element is a text node, this will return the text value of that node.
Get the value of the attribute with the given name.
Iterate over child nodes.
Set the value of the attribute with the given name.
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
For those that can't live without JavaScript DOM-compatible method names.
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.
The class name of this element.
Simluate a click on the element. You can optionally specify that a different button was clicked (defaults to "left" – can be "left", "middle", or "right") or that shift/ctrl are held down at the time of click.
Get elements in the document (optionally with a given tag name) that have a certain class.
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().
Get elements by tag name given a certain namespace.
Check whether an attribute exists in this element.
The anchor's 'href' value. Returns the full URL pointed to by the href attribute of this element.
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.
Syntactic sugar for isinstance.
Like tagName but this won't convert things to lower. Only really useful if you're dealing with XML, which probably isn't the case anyway!
Get the lowercase name of this tag.
If the next child of this element is a text node, this will return the text value of that node.
Form elements contain input elements. You can submit a form with
Form.submit.
Get the value of the attribute with the given name.
Iterate over child nodes.
Set the value of the attribute with the given name.
The action for this form (the page to which data is to be submited).
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
For those that can't live without JavaScript DOM-compatible method names.
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.
The class name of this element.
Simluate a click on the element. You can optionally specify that a different button was clicked (defaults to "left" – can be "left", "middle", or "right") or that shift/ctrl are held down at the time of click.
Get elements in the document (optionally with a given tag name) that have a certain class.
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().
Get elements by tag name given a certain namespace.
Check whether an attribute exists in this element.
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.
Syntactic sugar for isinstance.
The method with which this form is to be submitted (GET, POST, etc).
Like tagName but this won't convert things to lower. Only really useful if you're dealing with XML, which probably isn't the case anyway!
Reset the data in the form.
Submit the form to the page specified in the action. The callback given is like one you would pass to pykthml.Browser.load.
Get the lowercase name of this tag.
If the next child of this element is a text node, this will return the text value of that node.
Input elements that you can set the value/name of.
Get the value of the attribute with the given name.
Iterate over child nodes.
Set the value of the attribute with the given name.
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
For those that can't live without JavaScript DOM-compatible method names.
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.
The class name of this element.
Simulate a click on the input element. If this is a submit button, for example, this clicks it.
Get the form element this input resides in.
Get elements in the document (optionally with a given tag name) that have a certain class.
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().
Get elements by tag name given a certain namespace.
Check whether an attribute exists in this element.
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.
Syntactic sugar for isinstance.
The HTML name of this input.
Like tagName but this won't convert things to lower. Only really useful if you're dealing with XML, which probably isn't the case anyway!
Get the lowercase name of this tag.
If the next child of this element is a text node, this will return the text value of that node.
The value of this input – for example, for textareas and inputs of type 'text', this is its content. For buttons, this is the text inside the button, etc.
A text node lets you access the text in it using the
Text.value attribute or by converting to a string with str().
Iterate over child nodes.
Text.value converts the string to a regular string via str(). This gives the unicode version.
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
For those that can't live without JavaScript DOM-compatible method names.
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.
Syntactic sugar for isinstance.
Equivalent to unicode(textNode). Get the string this node represents.
Textareas. Just like
Inputs really ;-).
Get the value of the attribute with the given name.
Iterate over child nodes.
Set the value of the attribute with the given name.
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
For those that can't live without JavaScript DOM-compatible method names.
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.
The class name of this element.
Simulate a click on the input element. If this is a submit button, for example, this clicks it.
Get the form element this textarea resides in.
Get elements in the document (optionally with a given tag name) that have a certain class.
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().
Get elements by tag name given a certain namespace.
Check whether an attribute exists in this element.
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.
Syntactic sugar for isinstance.
The HTML name of this input.
Like tagName but this won't convert things to lower. Only really useful if you're dealing with XML, which probably isn't the case anyway!
Get the lowercase name of this tag.
If the next child of this element is a text node, this will return the text value of that node.
The content of this textarea.