gpt4 book ai didi

node.js - Nightmare.js代码卡在评估/然后

转载 作者:行者123 更新时间:2023-12-03 13:24:14 25 4
gpt4 key购买 nike

基于github page的示例,我编写了以下代码:

// There is some stuff before this that loads the page and do a few clicks but it's not relative to the problem

var selector = 'ContentPlaceHolder1_dtlA_lnkB_0';
nightmare
.evaluate(function (selector) {
return document.querySelector(selector).innerText;
}, selector)
.then(function(text) {
console.log(text);
})

但是,当我运行代码时,它卡住了,没有任何输出。浏览器甚至没有出现。
DEBUG=nightmare node checkjobs.js    
nightmare queuing process start +0ms
nightmare queueing action "goto" for http://xxxxxxxxx/Login.aspx +3ms
nightmare queueing action "type" +2ms
nightmare queueing action "type" +0ms
nightmare queueing action "click" +0ms
nightmare queueing action "wait" +0ms
nightmare queueing action "click" +0ms
nightmare queueing action "wait" +0ms
nightmare queueing action "click" +0ms
nightmare queueing action "evaluate" +0ms
nightmare running +1ms
nightmare running +16ms

但是,如果我评论.then部分。其余代码正常,浏览器出现并执行所有步骤。

HTML看起来像这样:
<a id="CContentPlaceHolder1_dtlA_lnkB_0" class="LinkButonDark" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$dtlA$ctl00$lnkB','')" style="color: #97c1e2; text-transform: capitalize;"><b>SOME TEXT I NEED TO CAPTURE</b></a>

我究竟做错了什么?

最佳答案

在他们的示例中,我总是在.then()之前看到.end()

试试这个:

var selector = 'ContentPlaceHolder1_dtlA_lnkB_0';
nightmare
.evaluate(function (selector) {
return document.querySelector(selector).innerText;
}, selector)
.end()
.then(function(text) {
console.log(text);
})

关于node.js - Nightmare.js代码卡在评估/然后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42446022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com