【问题标题】:Nightmare hangs on goto()噩梦挂在 goto() 上
【发布时间】:2017-04-26 21:54:12
【问题描述】:

我最近一直在使用 NightmareJS,但现在遇到了问题。似乎每当我尝试使用 Nightmare 加载页面并等待选择器存在时,它都会挂在 goto 调用上。我有以下代码,打印到控制台的唯一内容是“正在加载”。

nm = new Nightmare({show: false});

console.log("loading");

nm.goto("https://www.google.com")

.then(() => {
  return nm.wait(".gbqfba")
  .then(() => {
    console.log("search bar loaded, showing browser");
    nm.show();
  })
  .catch((err) => {
    console.log(err.toString());
  })
})
.catch(error => console.log('An error occurred:', error));

(类 'gbqfba' 是我等待的搜索栏的隐藏部分,所以我知道搜索栏已加载)

【问题讨论】:

  • 您确定是goto 阻塞而不是wait?也许 goto 的then 中的控制台日志会很清楚?因为在我看来,gbqfba 不是一个类,而是一个 ID(所以需要 # 而不是 .)
  • @Vasan 我尝试了您的建议,但没有记录任何内容。我从中得到的只是一个像这样的窗口:prntscr.com/f18qnl。另外,正如我所见,我所指的元素 实际上是一个类,但如果我错了,请纠正我:prntscr.com/f18nl1

标签: node.js headless-browser nightmare


【解决方案1】:

nightmare.show() 不再是函数,需要在初始化时设置。要查看 nightmare 的渲染器窗口,需要通过

var nightmare = Nightmare({ show: true });

另外,您可以打开开发者工具,这样您就可以手动检查是否 document.querySelector(".gbqfba");正在工作。

var nightmare = Nightmare({
   openDevTools: true,
   show: true
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-21
    • 2020-03-14
    • 2010-11-13
    • 2010-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多