我希望在噩梦中使用script.js
时从加载的.evaluate()
中获取值。所以,让我们说在某些网站上有这个基本的HTML ...
<!doctype html>
<head>
<title> far-away-website.com</title>
<script src="script.js"></script>
<script src="script-two.js"></script>
</head>
<body>
<div> DOM stuff</div>
</body>
</html>
而且script.js
有这个......
func.prototype.hasData = function() {
return this.data
}
如何在梦魇中从this.data
获取.evaluate()
的值?...
var Nightmare = require('nightmare');
var nightmare = Nightmare({
// waitTimeout: 60000, // in ms
openDevTools: {
//mode: 'detach'
},
show: true
})
nightmare.goto('https://www.far-away-website.com')
.evaluate(() => {
return this.data // needed from script.js
})
.then((data) => {
console.log(data)
})
P.S。在chrome dev工具中使用this.data
可以看到watch
的值。