Last active
February 11, 2019 12:05
-
-
Save k0d3d/4ef429f1a6efcec553361914eca40310 to your computer and use it in GitHub Desktop.
Async function with nightmare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = async function (context, req) { | |
// keep ur module imports within | |
// this exported function | |
const Nightmare = require("nightmare"); | |
const nightmare = Nightmare() | |
// @returns Promise | |
let n = nightmare | |
.goto('https://duckduckgo.com') | |
.type('#search_form_input_homepage', 'github nightmare') | |
.click('#search_button_homepage') | |
.wait('#links .result__a') | |
.evaluate(() => document.querySelector('#links .result__a').href) | |
.end() | |
let link = await n | |
context.res = { | |
body: `this is the link ${link}` | |
} | |
// U might not have to call | |
// this because its an async function | |
// context.done() | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment