从梦魇请求中获取数据的评估数据和cookie

时间:2017-11-16 07:24:11

标签: node.js nightmare

如何在一场噩梦请求中提出一个请求以获取document.titlecookies

const Nightmare = require('nightmare')

Nightmare()
    .goto('http://cnn.com')
    .evaluate(() => document.title)
    .end()
    .then(console.log)

Nightmare()
    .goto('http://cnn.com')
    .cookies.get()
    .end()
    .then(console.log)

1 个答案:

答案 0 :(得分:0)

这有效:

const Nightmare = require('nightmare')
const nightmare = Nightmare()

async function example () {
    const call = nightmare
        .goto('http://cnn.com')

    const title = await call
        .evaluate(() => document.title)

    const cookies = await call
        .cookies.get()

    await call.end()
    return {title, cookies}
}