{"id":57,"date":"2016-07-18T21:44:16","date_gmt":"2016-07-18T21:44:16","guid":{"rendered":"http:\/\/wizardofbots.com\/network\/?p=57"},"modified":"2016-07-18T22:28:01","modified_gmt":"2016-07-18T22:28:01","slug":"reach-nirvana-using-nightmarejs","status":"publish","type":"post","link":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/","title":{"rendered":"Automate browser with Javascript and Electron using NightmareJS"},"content":{"rendered":"<p>Damn, this is so fucking awesome. Automating your browser using <a href=\"http:\/\/electron.atom.io\/\">Electron<\/a> with <a href=\"https:\/\/github.com\/segmentio\/nightmare\">NightmareJS<\/a>. Electron is being funded by Github and its competitor is NWJS funded by Intel. So we have a good platform to simulate browser and interact with it. Using <a href=\"http:\/\/phantomjs.org\/\">PhantomJS<\/a> on its core.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/media.giphy.com\/media\/8Lx71V31BB0A\/giphy.gif\" width=\"500\" height=\"300\" \/><\/p>\n<p>So if you want to start just make sure you have installed everything for the NodeJS dev environment, that includes:<\/p>\n<pre><code class=\"language-bash\">curl -sL https:\/\/deb.nodesource.com\/setup_6.x <span class=\"token operator\">|<\/span> <span class=\"token function\">sudo<\/span> -E <span class=\"token function\">bash<\/span> -\r\nsudo apt-get install -y build-essential nodejs nodejs-legacy npm\r\nsudo npm install -g nightmare\r\n<\/code><\/pre>\n<p>Once you have it, you can copy any of this examples and type: node file.js<\/p>\n<p>Yahoo search example:<\/p>\n<pre class=\"lang:js decode:true \">var Nightmare = require('nightmare');\r\nvar nightmare = Nightmare({ show: true })\r\n\r\nnightmare\r\n  .goto('http:\/\/yahoo.com')\r\n  .type('form[action*=\"\/search\"] [name=p]', 'github nightmare')\r\n  .click('form[action*=\"\/search\"] [type=submit]')\r\n  .wait('#main')\r\n  .evaluate(function () {\r\n    return document.querySelector('#main .searchCenterMiddle li a').href\r\n  })\r\n  .end()\r\n  .then(function (result) {\r\n    console.log(result)\r\n  })\r\n  .catch(function (error) {\r\n    console.error('Search failed:', error);\r\n  });<\/pre>\n<p>Save this as yahoo.js and run it: <strong>node yahoo.js \u00a0<\/strong><\/p>\n<p>You can check the whole API Documentation on its repo in github: <a href=\"https:\/\/github.com\/segmentio\/nightmare\">https:\/\/github.com\/segmentio\/nightmare<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Damn, this is so fucking awesome. Automating your browser using Electron with NightmareJS. Electron is being funded by Github and its competitor is NWJS funded by Intel. So we have a good platform to simulate browser and interact with it. Using PhantomJS on its core. So if you want to start just make sure you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[33],"tags":[34,35],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-automation","tag-nightmarejs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Automate browser with Javascript and Electron using NightmareJS - Wizard Of Bots<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automate browser with Javascript and Electron using NightmareJS - Wizard Of Bots\" \/>\n<meta property=\"og:description\" content=\"Damn, this is so fucking awesome. Automating your browser using Electron with NightmareJS. Electron is being funded by Github and its competitor is NWJS funded by Intel. So we have a good platform to simulate browser and interact with it. Using PhantomJS on its core. So if you want to start just make sure you [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/\" \/>\n<meta property=\"og:site_name\" content=\"Wizard Of Bots\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-18T21:44:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-07-18T22:28:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/media.giphy.com\/media\/8Lx71V31BB0A\/giphy.gif\" \/>\n<meta name=\"author\" content=\"wizardofbots\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"wizardofbots\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/\",\"url\":\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/\",\"name\":\"Automate browser with Javascript and Electron using NightmareJS - Wizard Of Bots\",\"isPartOf\":{\"@id\":\"http:\/\/wizardofbots.com\/network\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/media.giphy.com\/media\/8Lx71V31BB0A\/giphy.gif\",\"datePublished\":\"2016-07-18T21:44:16+00:00\",\"dateModified\":\"2016-07-18T22:28:01+00:00\",\"author\":{\"@id\":\"http:\/\/wizardofbots.com\/network\/#\/schema\/person\/31f9e486da1c11791d94a861854a2a9f\"},\"breadcrumb\":{\"@id\":\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#primaryimage\",\"url\":\"https:\/\/media.giphy.com\/media\/8Lx71V31BB0A\/giphy.gif\",\"contentUrl\":\"https:\/\/media.giphy.com\/media\/8Lx71V31BB0A\/giphy.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/wizardofbots.com\/network\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automate browser with Javascript and Electron using NightmareJS\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/wizardofbots.com\/network\/#website\",\"url\":\"http:\/\/wizardofbots.com\/network\/\",\"name\":\"Wizard Of Bots\",\"description\":\"Botting and AI community\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/wizardofbots.com\/network\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/wizardofbots.com\/network\/#\/schema\/person\/31f9e486da1c11791d94a861854a2a9f\",\"name\":\"wizardofbots\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/wizardofbots.com\/network\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/2.gravatar.com\/avatar\/584eebc303f64610559ab9f305f6928d?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/2.gravatar.com\/avatar\/584eebc303f64610559ab9f305f6928d?s=96&d=mm&r=g\",\"caption\":\"wizardofbots\"},\"url\":\"http:\/\/wizardofbots.com\/network\/author\/wizardofbots\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Automate browser with Javascript and Electron using NightmareJS - Wizard Of Bots","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/","og_locale":"en_US","og_type":"article","og_title":"Automate browser with Javascript and Electron using NightmareJS - Wizard Of Bots","og_description":"Damn, this is so fucking awesome. Automating your browser using Electron with NightmareJS. Electron is being funded by Github and its competitor is NWJS funded by Intel. So we have a good platform to simulate browser and interact with it. Using PhantomJS on its core. So if you want to start just make sure you [&hellip;]","og_url":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/","og_site_name":"Wizard Of Bots","article_published_time":"2016-07-18T21:44:16+00:00","article_modified_time":"2016-07-18T22:28:01+00:00","og_image":[{"url":"https:\/\/media.giphy.com\/media\/8Lx71V31BB0A\/giphy.gif"}],"author":"wizardofbots","twitter_card":"summary_large_image","twitter_misc":{"Written by":"wizardofbots","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/","url":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/","name":"Automate browser with Javascript and Electron using NightmareJS - Wizard Of Bots","isPartOf":{"@id":"http:\/\/wizardofbots.com\/network\/#website"},"primaryImageOfPage":{"@id":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#primaryimage"},"image":{"@id":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#primaryimage"},"thumbnailUrl":"https:\/\/media.giphy.com\/media\/8Lx71V31BB0A\/giphy.gif","datePublished":"2016-07-18T21:44:16+00:00","dateModified":"2016-07-18T22:28:01+00:00","author":{"@id":"http:\/\/wizardofbots.com\/network\/#\/schema\/person\/31f9e486da1c11791d94a861854a2a9f"},"breadcrumb":{"@id":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#primaryimage","url":"https:\/\/media.giphy.com\/media\/8Lx71V31BB0A\/giphy.gif","contentUrl":"https:\/\/media.giphy.com\/media\/8Lx71V31BB0A\/giphy.gif"},{"@type":"BreadcrumbList","@id":"http:\/\/wizardofbots.com\/network\/reach-nirvana-using-nightmarejs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/wizardofbots.com\/network\/"},{"@type":"ListItem","position":2,"name":"Automate browser with Javascript and Electron using NightmareJS"}]},{"@type":"WebSite","@id":"http:\/\/wizardofbots.com\/network\/#website","url":"http:\/\/wizardofbots.com\/network\/","name":"Wizard Of Bots","description":"Botting and AI community","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/wizardofbots.com\/network\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/wizardofbots.com\/network\/#\/schema\/person\/31f9e486da1c11791d94a861854a2a9f","name":"wizardofbots","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/wizardofbots.com\/network\/#\/schema\/person\/image\/","url":"http:\/\/2.gravatar.com\/avatar\/584eebc303f64610559ab9f305f6928d?s=96&d=mm&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/584eebc303f64610559ab9f305f6928d?s=96&d=mm&r=g","caption":"wizardofbots"},"url":"http:\/\/wizardofbots.com\/network\/author\/wizardofbots\/"}]}},"_links":{"self":[{"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/posts\/57"}],"collection":[{"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":6,"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":63,"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/posts\/57\/revisions\/63"}],"wp:attachment":[{"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wizardofbots.com\/network\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}