webapi¶
The webapi is the latest package to be added to domonic.
console¶
from domonic.webabi.console import console
console.log("Hello World")
encoding¶
from domonic.webabi.encoding import TextEncoder, TextDecoder
encoder = TextEncoder()
fetch¶
from domonic.webabi.fetch import fetch
URL¶
url is a wrapper around the urlparse and urlencode functions in python.
from domonic.webabi.url import URL
myurl = URL("http://www.google.com/search?q=domonic")
print(myurl.host)
print(myurl.query)
print(myurl.query.q)
print(myurl.query.q.value)
for more information see mdn docs… # TODO - link
XPATH¶
Here’s a quick example of using xpath…
from domonic.webapi.xpath import XPathEvaluator, XPathResult
somehtml = '''
<div>XPath example</div>
<div>Number of <div>s: <output></output></div>
'''
page = domonic.parseString(somehtml) # NOTE - probably requries html5lib install
evaluator = XPathEvaluator()
expression = evaluator.createExpression("//div")
result = expression.evaluate(page, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE)
assert result.snapshotLength == 2
for more information see mdn docs… # TODO - link
domonic.webapi.console¶
https://developer.mozilla.org/en-US/docs/Web/API/Console_API
domonic.webapi.encoding¶
https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API
- class domonic.webapi.encoding.TextDecoderStream(encoding='utf-8')[source]
- class domonic.webapi.encoding.TextEncoderStream(encoding='utf-8')[source]
domonic.webapi.fetch¶
domonic.webapi.url¶
https://developer.mozilla.org/en-US/docs/Web/API/URL
# TODO - move the unit tests for this class from javascript to webapi # TODO - untested
- class domonic.webapi.url.URL(url: str = '', *args, **kwargs)[source]
a-tag extends from URL
- property hash
” hash Sets or returns the anchor part (#) of a URL
- class domonic.webapi.url.URLSearchParams(paramString)[source]
[utility methods to work with the query string of a URL]
- append(key, value)[source]
Appends a specified key/value pair as a new search parameter
- delete(key)[source]
Deletes the given search parameter, and its associated value, from the list of all search parameters.
- entries()[source]
Returns an iterator allowing iteration through all key/value pairs contained in this object.
- forEach(func)[source]
Allows iteration through all values contained in this object via a callback function.
- get(key)[source]
Returns the first value associated with the given search parameter.
- getAll(key)[source]
Returns all the values associated with a given search parameter.
- has(key)[source]
Returns a Boolean indicating if such a given parameter exists.
- keys()[source]
Returns an iterator allowing iteration through all keys of the key/value pairs contained in this object.
- set(key, value)[source]
Sets the value associated with a given search parameter to the given value. If there are several values, the others are deleted.
- sort()[source]
Sorts all key/value pairs, if any, by their keys.
- toString()[source]
Returns a string containing a query string suitable for use in a URL.
- values()[source]
Returns an iterator allowing iteration through all values of the key/value pairs contained in this object.
domonic.webapi.XMLHttpRequest¶
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
domonic.webapi.xpath¶
https://developer.mozilla.org/en-US/docs/Glossary/XPath
uses elementpath lib.
- TODO - content strings must be TextNodes for it to work.
so will have to iterate and update them. i.e. Treewalker