卡斯珀;开幕动态 url

CasperJS; opening dynamic url

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

这适用于 user 变量,它来自终端。然而 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')   
})

你可以通过扭曲 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')   
  })
})