【问题标题】:how to make conditional loop click event with nightmare on node?如何在节点上使用噩梦制作条件循环点击事件?
【发布时间】:2017-06-19 05:47:17
【问题描述】:

我正在制作网页爬虫。 所以我用的是node+nightmare。

我要抓取的网页有“加载更多”按钮。 当我单击此按钮时,会像任何其他网页一样加载更多帖子。

问题是 - 此页面上的帖子数量可能会发生变化。所以我的爬虫应用程序不知道按了多少次“加载更多”按钮。

我知道噩梦中有一个“存在”apu,但我想在条件下重复使用它,而不是一次或固定数字循环。

有什么逻辑我可以使用这种情况吗? 谁来帮帮我T_T

【问题讨论】:

    标签: javascript node.js web-crawler nightmare


    【解决方案1】:

    你可以看看我的回答Repeatedly Clickling

    您可以在相同的代码中设置条件:

    function next() {
      if(condition)
      BETHESDA.wait('div[data-is="main-mods-pager"] > button')
        .click('div[data-is="main-mods-pager"] > button')
        .then(function() {
          console.log("click done");
          next();
        })
        .catch(function(err) {
          console.log(err);
          console.log("All done.");
        });
    }
    
    function condition() {
      //Your condition code goes here
      //return true or false
    }
    

    我认为这应该是一个重复的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多