【发布时间】:2013-09-09 20:24:33
【问题描述】:
我正在尝试为hubot 编写一个脚本来获取游戏的玩家统计数据,但是我在列表理解方面遇到了一些问题。
这是我的代码
listings = []
listings =
(for player in players
request "http://pwa.wp3.pl/curvefever/?player=" + player , (err, res, body)->
$ = cheerio.load(body)
msg.send "Hello, world!1"
{name: $('b').slice(0).eq(0).text().toLowerCase(), rank: parseInt($('td').slice(37).eq(0).text(),10)})
msg.send "Hello, world!2"
for player of listings
msg.send "Hello, world!3"
msg.send player.name + " " + player.rank
运行此程序时,我得到“Hello, world!2”,后跟几个“Hello, world!1”,没有“Hello, world!3”,因为列表(可能)是空的。
当我执行 msg.send 而不是尝试捕获数组中的列表时,该脚本有效,但是我也想根据排名对列表进行排序。
【问题讨论】:
标签: coffeescript hubot