【发布时间】:2014-02-12 11:50:08
【问题描述】:
我正在用 phantomjs 编写一些咖啡脚本来截取多个 url。不过,每次我尝试运行它时,都会收到一条错误消息,Can't open <filename>。是什么赋予了?这是我的代码:
page = require('webpage').create()
page.viewportSize =
width: 1024
height: 760
urls = phantom.args
i = 1
for url in urls
do (url) ->
output = "screenshot-#{i}.png"
page.open url, (status) ->
if status isnt 'success'
console.log "Error opening url \"#{page.reason_url}\": #{page.reason}"
phantom.exit(1)
else
console.log "Page opened.."
window.setTimeout (->
page.clipRect =
top: 0
left: 0
width: 1024
height: 760
page.render(output)
), 200
i += 1
phantom.exit()
我尝试注释掉,似乎失败的部分是 page.open(url)。奇怪的是错误消息说文件本身无法打开。
【问题讨论】:
-
您是否尝试将“google.com”附加为第一个网址?也许错误消息是有效的。
-
是的,我尝试直接输入一个字符串,但它似乎没有工作:(
-
尝试硬编码?喜欢
urls = ['http://google.com'] -
这似乎也不起作用。我已经用一个简单的
page.open 'http://www.google.com', (status)-> console.log "--->#{status}"将它简化到最低限度,但我得到了同样的错误Can't open 'test.js.coffee'我开始认为 phantomjs 的 open 方法有什么问题。 -
我认为这归结为这段代码不起作用:
page.open('http://github.com/', (status)-> console.log("Status: #{status}") page.render('github.png') )
标签: coffeescript screenshot phantomjs