<protected> new Command(parent)
An Osmosis command.
Parameters:
| Name | Type | Description |
|---|---|---|
parent |
object | parent instance |
Returns:
Command
Members
-
document
-
Change context to the current Document.
- See:
-
- Command.doc
Properties:
Name Type Description document -
window
-
Change context to the current Window.
Properties:
Name Type Description window
Methods
-
click(selector)
-
Click an HTML element and continue after all events finish.
Parameters:
Name Type Description selectorSelector Node(s) to click Example
.click('#nav > a') .then(function(window) { var ajax = window.document.querySelector("#ajaxContent"); if (ajax.textContent.length > 0) { this.log("ajax loaded"); } }) -
config(option, value)
-
Set configuration options for the **preceeding** command on down the chain.
Parameters:
Name Type Argument Description optionstring | object A `key` string or { key: value } object valuestring <optional>
A value for the given `key` - See:
-
- Osmosis.options
- Osmosis.config
-
cookie(name, value)
-
Set a cookie. Short for `.config({ cookies: ... })`. Note: Setting a cookie to `null` will delete the cookie.
Parameters:
Name Type Description namestring Cookie name valuestring Cookie value - See:
-
- Osmosis.config
- Command.config
-
data(callback)
-
Calls a callback with the current {@data} object. Note: Don't use this command to modify the {@data} object. Please use Command.then instead.
Parameters:
Name Type Description callbackfunction A callback with an argument for {@data} -
delay(delay)
-
Delay each context before continuing down the chain.
Parameters:
Name Type Description delaynumber A number of milliseconds or a float of seconds. -
do(function)
-
Execute each argument asynchronously using the current context and data. After each argument has finished, Command.do will continue to the immediately following command using the original context.
Parameters:
Name Type Argument Description functionOsmosis | middlewareCallback <repeatable>
Callbacks or instances -
done(function)
-
Call a callback when the Osmosis instance has completely finished.
Parameters:
Name Type Description functionfunction Callback function -
fail(selector)
-
Continue if the given selector does NOT match any nodes. If a node is found, a Command.error message well be sent.
Parameters:
Name Type Description selectorSelector A selector to match. - See:
-
- Command.login
- Command.filter
-
filter(match)
-
Check that the context node matches the given selector.
Parameters:
Name Type Description matchSelector A Selector to match -
find(selector)
-
Search for nodes in the current Document.
Parameters:
Name Type Description selectorSelector | contextCallback | Command.learn - See:
-
- Command.select
-
follow(selector)
-
Follow a url.
Parameters:
Name Type Description selectorSelector A selector string for link nodes -
follow(match)
-
Continue if the context node contains the given string.
Parameters:
Name Type Description matchstring | RegExp A string to match. -
get(url, params)
-
Make an HTTP GET request.
Parameters:
Name Type Argument Description urlstring | contextCallback An absolute or relative URL or a contextCallback that calls a URL. paramsobject <optional>
HTTP GET query parameters - See:
-
- Command.post
-
header(name, value)
-
Set an HTTP header. Short for `.config({ headers: ... })`
Parameters:
Name Type Description namestring Header name valuestring Header value - See:
-
- Osmosis.headers
- Osmosis.config
-
headers(headers)
-
Set multiple HTTP headers. Short for `.config({ headers: ... })`.
Parameters:
Name Type Description headersobject { headerName: headerValue, ... } - See:
-
- Osmosis.header
- Osmosis.config
-
learn(name)
-
Osmosis learns to find dynamic content via static selectors.
Parameters:
Name Type Description namestring The name of the runtime variable - See:
-
- Command.use
-
login(username, password)
-
Log in using a web page's login form.
Parameters:
Name Type Description usernamestring Username or email address passwordstring Password - See:
-
- Command.success
- Command.fail
-
match(match)
-
Continue if the context node innerText matches a RegExp.
Parameters:
Name Type Description matchstring | RegExp A RegExp to match. -
paginate(selector, limit)
-
Loads multiple pages. The first argument can alternatively be an object representing HTTP GET/POST parameters to modify. If the first argument is an object, numeric values will increment the existing parameter value by that amount. String values are treated as selectors and each corresponding parameter's value will be replaced with the content of the selected node.
Parameters:
Name Type Argument Description selectorselector A link or form to the next page. limitnumber | Selector | middlewareCallback <optional>
Total number of pages to load. -
parse(data, options)
-
Parse HTML or XML data
Parameters:
Name Type Description datastring | buffer XML/HTML data optionsobject Parse options - See:
-
- Osmosis.parse
-
pause()
-
Pause an Osmosis instance.
-
post(url, data)
-
Make an HTTP POST request.
Parameters:
Name Type Argument Description urlstring | contextCallback An absolute or relative URL or a contextCallback that calls a URL. dataobject <optional>
HTTP POST data - See:
-
- Command.get
-
proxy(proxy)
-
Set a proxy. Short for `.config({ proxy: ... })`
Parameters:
Name Type Description proxystring | array A string or array of HTTP proxy URL(s) - See:
-
- Osmosis.config
-
resume()
-
Resume an Osmosis instance.
-
select(selector)
-
Search for nodes in the current context.
Parameters:
Name Type Description selectorSelector | contextCallback | Command.learn A selector - See:
-
- Command.find
-
set(data)
-
Set values in the data object. Note: Also accepts set(key, selector) as parameters
Parameters:
Name Type Description dataobject Key/selector pairs to set. -
stop()
-
Stop an Osmosis instance.
-
submit(selector, params)
-
Submit a form.
Parameters:
Name Type Description selectorSelector A selector for a paramsobject Keys/values for the form's inputs. -
success(selector)
-
Continue if the given selector matches any nodes. If no nodes are found, a Command.error message will be sent.
Parameters:
Name Type Description selectorSelector A selector to match. - See:
-
- Command.login
- Command.filter
-
then(callback)
-
Execute a given callback.
Parameters:
Name Type Description callbackcallback -
train(object)
-
Teach Osmosis how to find content.
Parameters:
Name Type Description objectobject { name: selector } pairs of training variables - See:
-
- Command.learn
-
trigger(event, selector)
-
Trigger a DOM event and continue once it completes. Note: If no selector is specified, the default event target will be the Window object.
Parameters:
Name Type Argument Description eventstring The name of the event to trigger. selectorSelector <optional>
Nodes to trigger the event on. -
use()
-
Use a runtime defined variable
- See:
-
- Command.run
- Command.learn
-
using(object)
-
Set variables to use.
Parameters:
Name Type Description objectobject { key: value } pairs of variables - See:
-
- Command.use