【问题标题】:CasperJS continuously test if selector existsCasperJS 不断测试选择器是否存在
【发布时间】:2014-10-20 16:28:53
【问题描述】:

我正在使用 casperjs 进行一些抓取,并且在运行脚本时,我还应该测试是否出现了技术困难页面。这个页面在浏览网站时随时可能出现,所以我不能一开始就放一个测试,它应该不断测试。 CasperJS/PhantomJS 中有没有办法,比如监听器之类的?

应该运行这个:

casper.checkIfThereIsTechError = function() {
    return casper.evaluate(function() {
        return __utils__.exists({
            type: 'xpath',
            path: '//a[@href="......'
        });
    });
};

【问题讨论】:

    标签: javascript phantomjs casperjs


    【解决方案1】:

    在 casper js 中,一切都表示为一个步骤。在每个步骤中,首先调用你的函数来检查错误

      casper.then(
      function(){
       isErrorexists = casper.checkIfThereIsTechError()
       if (!isErrorexists){
        do what you want to do here...
           }
         }
      )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2019-01-04
      • 1970-01-01
      • 2018-11-21
      • 2014-02-01
      • 1970-01-01
      • 2011-03-19
      相关资源
      最近更新 更多