【发布时间】:2017-01-31 16:08:53
【问题描述】:
我正在尝试使用噩梦,在节点js中根据链接的锚文本内的文本点击链接。
下面是一些示例代码:
var Nightmare = require('nightmare');
var nightmare = Nightmare({show: true})
nightmare
.goto('https://www.wikipedia.org/')
.inject('js', 'C:/users/myname/desktop/nodejs/node_modules/jquery/dist/jquery.js')
.wait(500)
var selector = 'a';
nightmare
.evaluate(function (selector) {
// now we're executing inside the browser scope.
return document.querySelector(selector).innerText;
}, selector) // <-- that's how you pass parameters from Node scope to browser scope
.end()
.then(function(result) {
console.log(result)
})
我真的不清楚为什么所有标签的内部文本都没有返回?我想我可以在 .evalution 方法中做一个 if 语句,这样它就会将要点击的链接限制为“English”。
知道如何根据链接文本点击链接吗?
【问题讨论】: