【问题标题】:CasperJS; opening dynamic url卡斯珀JS;打开动态网址
【发布时间】:2016-08-21 02:25:03
【问题描述】:

我正在使用 casperJS 来获取一个页面并从 URL 中收集一个 id,这就是我的 start 函数正在做的事情。然后我想将 id 放入一个新的 url 并去那里。

这适用于user var,它来自终端。但是sid 是未定义的,而不是我将其更新为的值。

任何帮助将不胜感激。我想知道我是否发现了 casperJS 的限制。请不要说这不是完整的代码(因为那要长得多),如果您给我发消息,我可以为您提供整个脚本。

var user = decodeURIComponent(casper.cli.get(0).replace(/\+/g, ' '))

var sid 
casper.start('https://editor.storify.com/', function() {
    sid = this.getCurrentUrl()
    sid = sid.split('/')[3]
})
casper.thenOpen('https://storify.com/' + sid, function() {
   console.log('lets view the posts')
   console.log(token)
   console.log(sid)
   if (dev)
      this.capture('storeheading.png')   
})

【问题讨论】:

    标签: javascript casperjs


    【解决方案1】:

    您可以通过在 then 内部扭曲 thenOpen 来解决此问题

    casper.then(function() {
      casper.thenOpen('https://storify.com/' + sid, function() {
      console.log('lets view the posts')
      console.log(token)
      console.log(sid)
      if (dev)
        this.capture('storeheading.png')   
      })
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多