我在评论示例中为您提供了所需的内容。如果你仍然面临问题,请提问。
const express = require('express')
const Nightmare = require("nightmare")
const app = express()
app.get('/', async function (req, res) {
const nightmare = Nightmare({ show: false})
const url = 'https://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux'
await nightmare.goto(url)
await nightmare.wait(2000)
const result = await nightmare.evaluate(
() => document.querySelector('#toc > ul').innerText
)
res.send(result)
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})