Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. var co = require("co");
  2. var Nightmare = require("nightmare");
  3. require("nightmare-xpath"); // xpath function will be added to prototype.
  4.  
  5. co(function*() {
  6. var links = yield Nightmare()
  7. .goto("http://example.com/")
  8. .xpath("//a[@href]", function(node) {
  9. // We cannot return DOM element to nodejs,
  10. // we must return serializable object or primitive.
  11. // If function is omitted, node.toString() will be used.
  12. return {
  13. href: node.href,
  14. innerText: node.innerText
  15. };
  16. })
  17. .end();
  18. console.log("Found %d links:", links.length);
  19. console.log(links);
  20. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement