phantomjs和ajax请求

时间:2014-02-03 00:01:36

标签: jquery ajax coffeescript

我正在玩一些phantomjs和coffeescript,我想在访问一个网站后想要实现的,在他的页面中已经有jquery是要解雇一些ajax get请求 把数据还给我。我用firefox控制台玩了一下,效果很好。不幸的是,phantomjs什么也没有回来,我不知道为什么。

page = require('webpage').create()
system = require 'system'

url = 'http://www.testpage.com'
#page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js")
page.open url,
  (status) ->
    if status isnt 'success'
      console.log 'uanble to acces the netzwprk'
    else
      results = page.evaluate ->
        all = []
        list = $(".navigation .main")
        for item in list
          all.push(item.href)
        #return all
          $.get item.href, (data,status) ->
            console.log data.toSource()

      #console.log results.join('\n')
    phantom.exit()

THKS。求助volk。

克萨韦尔

1 个答案:

答案 0 :(得分:0)

我认为这是因为你必须等待phantomjs完成加载页面。你可以看到一些提示:https://code.google.com/p/phantomjs/issues/detail?id=265