https://github.com/unlight/nightmare-xpath
Nightmare plugin to select nodes by xpath expression.
https://github.com/unlight/nightmare-xpath
nightmare nightmare-plugin nightmare-xpath
Last synced: 12 months ago
JSON representation
Nightmare plugin to select nodes by xpath expression.
- Host: GitHub
- URL: https://github.com/unlight/nightmare-xpath
- Owner: unlight
- License: mit
- Created: 2015-03-20T10:05:37.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2020-09-25T19:29:01.000Z (over 5 years ago)
- Last Synced: 2025-03-25T05:41:36.429Z (about 1 year ago)
- Topics: nightmare, nightmare-plugin, nightmare-xpath
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# nightmare-xpath
Nightmare plugin to select nodes by xpath expression.
## INSTALL
This will install plugin `nightmare-xpath` for Nightmare 3.X:
```sh
npm install --save-dev nightmare-xpath
```
**Note:** If you are looking for plugin for Nightmare 1.X, then use:
```sh
npm install nightmare-xpath@1
```
## USAGE
```js
const Nightmare = require('nightmare');
require('nightmare-xpath')(Nightmare);
const links = await Nightmare()
.goto('http://example.com/')
.xpath('//a[@href]', function (node) {
// We cannot return DOM element to nodejs,
// we must return serializable object or primitive.
// If function is omitted, node.toString() will be used.
return node.href;
})
.then();
console.log(links); // ['https://www.iana.org/domains/example']
```
## API
`xpath(selector: string, handler?: (Node: node) => any): Array`
#### selector
Type: `string`
XPath expression.
#### handler
Type: `function`
Optional: Yes
Signature: `(Node: node) => any`
This function be called on each result of `XPathResult`.
We cannot return DOM element to nodejs,
we must return serializable object or primitive.
If function is omitted, node.toString() will be used.
## RESOURCES
- https://developer.mozilla.org/ru/docs/Web/API/Document/evaluate