Modules:

pykhtml.dom

class ElementNotFoundError (inherits Exception)

class Document (inherits object)

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.

getElementById(self, id)

Get a reference to an element in the page by its id attribute.

getElementsByClass(self, className, tagName='*')

Get elements in the document that have a certain class.

getElementsByTagName(self, name)

Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().

getElementsByTagNameNS(self, ns, name)

Get elements by tag name given a certain namespace.

serialized (read-only property)

Return a string that represents the DOM structure of this document, much like what is returned via innerHTML in JavaScript.

visit(self, text=None, callback=None, attributes=None, stripSpace=True)

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.

class Node (inherits object)

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.

__iter__(self)

Iterate over child nodes.

addEvent(self, eventName, func, capture=False)

This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.

childNodes (read-only property)

For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

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.

isA(self, klass)

Syntactic sugar for isinstance.

class Element (inherits Node)

An HTML element. It provides methods for:
And more.

__delitem__(self, name)

Delete an attribute.

__getitem__(self, name)

Get the value of the attribute with the given name.

__iter__(self)

Inherited from Node
Iterate over child nodes.

__setitem__(self, name, value)

Set the value of the attribute with the given name.

addEvent(self, eventName, func, capture=False)

Inherited from Node
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

Inherited from Node
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.

className (property)

The class name of this element.

click(self, button='left', shift=False, ctrl=False)

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.

getElementsByClass(self, className, tagName='*')

Get elements in the document (optionally with a given tag name) that have a certain class.

getElementsByTagName(self, name)

Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().

getElementsByTagNameNS(self, ns, name)

Get elements by tag name given a certain namespace.

hasAttribute(self, name)

Check whether an attribute exists in this element.

id (property)

The ID of this element.

innerHTML (property)

The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.

isA(self, klass)

Inherited from Node
Syntactic sugar for isinstance.

originalTagName (read-only property)

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!

removeEvent(self, eventName, func, capture=False)

Inherited from Node
Removes events that you've added with Element.addEvent.

tagName (read-only property)

Get the lowercase name of this tag.

text (read-only property)

If the next child of this element is a text node, this will return the text value of that node.

class Anchor (inherits Element)

Anchor elements with an Anchor.href property.

__delitem__(self, name)

Inherited from Element
Delete an attribute.

__getitem__(self, name)

Inherited from Element
Get the value of the attribute with the given name.

__iter__(self)

Inherited from Node
Iterate over child nodes.

__setitem__(self, name, value)

Inherited from Element
Set the value of the attribute with the given name.

addEvent(self, eventName, func, capture=False)

Inherited from Node
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

Inherited from Node
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.

className (property)

Inherited from Element
The class name of this element.

click(self, button='left', shift=False, ctrl=False)

Inherited from 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.

getElementsByClass(self, className, tagName='*')

Inherited from Element
Get elements in the document (optionally with a given tag name) that have a certain class.

getElementsByTagName(self, name)

Inherited from Element
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().

getElementsByTagNameNS(self, ns, name)

Inherited from Element
Get elements by tag name given a certain namespace.

hasAttribute(self, name)

Inherited from Element
Check whether an attribute exists in this element.

href (read-only property)

The anchor's 'href' value. Returns the full URL pointed to by the href attribute of this element.

id (property)

Inherited from Element
The ID of this element.

innerHTML (property)

Inherited from Element
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.

isA(self, klass)

Inherited from Node
Syntactic sugar for isinstance.

originalTagName (read-only property)

Inherited from Element
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!

removeEvent(self, eventName, func, capture=False)

Inherited from Node
Removes events that you've added with Element.addEvent.

tagName (read-only property)

Inherited from Element
Get the lowercase name of this tag.

text (read-only property)

Inherited from Element
If the next child of this element is a text node, this will return the text value of that node.

class Form (inherits Element)

Form elements contain input elements. You can submit a form with Form.submit.

__delitem__(self, name)

Inherited from Element
Delete an attribute.

__getitem__(self, name)

Inherited from Element
Get the value of the attribute with the given name.

__iter__(self)

Inherited from Node
Iterate over child nodes.

__setitem__(self, name, value)

Inherited from Element
Set the value of the attribute with the given name.

action (property)

The action for this form (the page to which data is to be submited).

addEvent(self, eventName, func, capture=False)

Inherited from Node
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

Inherited from Node
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.

className (property)

Inherited from Element
The class name of this element.

click(self, button='left', shift=False, ctrl=False)

Inherited from 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.

getElementsByClass(self, className, tagName='*')

Inherited from Element
Get elements in the document (optionally with a given tag name) that have a certain class.

getElementsByTagName(self, name)

Inherited from Element
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().

getElementsByTagNameNS(self, ns, name)

Inherited from Element
Get elements by tag name given a certain namespace.

hasAttribute(self, name)

Inherited from Element
Check whether an attribute exists in this element.

id (property)

Inherited from Element
The ID of this element.

innerHTML (property)

Inherited from Element
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.

isA(self, klass)

Inherited from Node
Syntactic sugar for isinstance.

method (property)

The method with which this form is to be submitted (GET, POST, etc).

originalTagName (read-only property)

Inherited from Element
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!

removeEvent(self, eventName, func, capture=False)

Inherited from Node
Removes events that you've added with Element.addEvent.

reset(self)

Reset the data in the form.

submit(self, callback)

Submit the form to the page specified in the action. The callback given is like one you would pass to pykthml.Browser.load.

tagName (read-only property)

Inherited from Element
Get the lowercase name of this tag.

text (read-only property)

Inherited from Element
If the next child of this element is a text node, this will return the text value of that node.

class Input (inherits Element)

Input elements that you can set the value/name of.

__delitem__(self, name)

Inherited from Element
Delete an attribute.

__getitem__(self, name)

Inherited from Element
Get the value of the attribute with the given name.

__iter__(self)

Inherited from Node
Iterate over child nodes.

__setitem__(self, name, value)

Inherited from Element
Set the value of the attribute with the given name.

addEvent(self, eventName, func, capture=False)

Inherited from Node
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

Inherited from Node
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.

className (property)

Inherited from Element
The class name of this element.

click(self)

Simulate a click on the input element. If this is a submit button, for example, this clicks it.

focus(self)

Focus the input.

form (read-only property)

Get the form element this input resides in.

getElementsByClass(self, className, tagName='*')

Inherited from Element
Get elements in the document (optionally with a given tag name) that have a certain class.

getElementsByTagName(self, name)

Inherited from Element
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().

getElementsByTagNameNS(self, ns, name)

Inherited from Element
Get elements by tag name given a certain namespace.

hasAttribute(self, name)

Inherited from Element
Check whether an attribute exists in this element.

id (property)

Inherited from Element
The ID of this element.

innerHTML (property)

Inherited from Element
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.

isA(self, klass)

Inherited from Node
Syntactic sugar for isinstance.

name (property)

The HTML name of this input.

originalTagName (read-only property)

Inherited from Element
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!

removeEvent(self, eventName, func, capture=False)

Inherited from Node
Removes events that you've added with Element.addEvent.

tagName (read-only property)

Inherited from Element
Get the lowercase name of this tag.

text (read-only property)

Inherited from Element
If the next child of this element is a text node, this will return the text value of that node.

value (property)

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.

class Text (inherits Node)

A text node lets you access the text in it using the Text.value attribute or by converting to a string with str().

__iter__(self)

Inherited from Node
Iterate over child nodes.

__unicode__(self)

Text.value converts the string to a regular string via str(). This gives the unicode version.

addEvent(self, eventName, func, capture=False)

Inherited from Node
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

Inherited from Node
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.

isA(self, klass)

Inherited from Node
Syntactic sugar for isinstance.

removeEvent(self, eventName, func, capture=False)

Inherited from Node
Removes events that you've added with Element.addEvent.

value (read-only property)

Equivalent to unicode(textNode). Get the string this node represents.

class TextArea (inherits Input)

Textareas. Just like Inputs really ;-).

__delitem__(self, name)

Inherited from Element
Delete an attribute.

__getitem__(self, name)

Inherited from Element
Get the value of the attribute with the given name.

__iter__(self)

Inherited from Node
Iterate over child nodes.

__setitem__(self, name, value)

Inherited from Element
Set the value of the attribute with the given name.

addEvent(self, eventName, func, capture=False)

Inherited from Node
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

Inherited from Node
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.

className (property)

Inherited from Element
The class name of this element.

click(self)

Inherited from Input
Simulate a click on the input element. If this is a submit button, for example, this clicks it.

focus(self)

Focus the textarea.

form (read-only property)

Get the form element this textarea resides in.

getElementsByClass(self, className, tagName='*')

Inherited from Element
Get elements in the document (optionally with a given tag name) that have a certain class.

getElementsByTagName(self, name)

Inherited from Element
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().

getElementsByTagNameNS(self, ns, name)

Inherited from Element
Get elements by tag name given a certain namespace.

hasAttribute(self, name)

Inherited from Element
Check whether an attribute exists in this element.

id (property)

Inherited from Element
The ID of this element.

innerHTML (property)

Inherited from Element
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.

isA(self, klass)

Inherited from Node
Syntactic sugar for isinstance.

name (property)

The HTML name of this input.

originalTagName (read-only property)

Inherited from Element
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!

removeEvent(self, eventName, func, capture=False)

Inherited from Node
Removes events that you've added with Element.addEvent.

tagName (read-only property)

Inherited from Element
Get the lowercase name of this tag.

text (read-only property)

Inherited from Element
If the next child of this element is a text node, this will return the text value of that node.

value (property)

The content of this textarea.