CasperJS“无法加载脚本” [英] CasperJS "unable to load script"

查看:58
本文介绍了CasperJS“无法加载脚本”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用casperJS编写新脚本时遇到最奇怪的问题。

I have the strangest issue while writing a new script for casperJS, which I use all the time.

当我尝试启动脚本时,使用 casperjs myScript .js,我得到以下内容:

When I try to launch the script, using "casperjs myScript.js, I get the following :

Unable to load script /var/www/scrapers/myScript.js; check file syntax

我检查了我的语法,没有发现任何错误,chmod + x该文件,对所有内容进行了sudo处理,仍然相同

I checked my syntax and found nothing wrong, chmod +x the file, sudoed everything, still the same.

即使是陌生人,我也从快速入门中复制了示例代码( http://docs.casperjs.org/en/latest/quickstart.html ),已保存和相同的消息...

Even stranger, I copypasted the example code from the quickstart (http://docs.casperjs.org/en/latest/quickstart.html), saved , and same message...

我在同一目录中的所有其他脚本都在工作,该怎么办?

All my other scripts in the same directory are working, what do I try now?

推荐答案

Re:我该怎么办?

Re: what do I try now?

您可以使用 xxd 查看文件内部。查看注释,现在您可以工作版本和非工作版本,因此可以并排比较它们以了解问题所在。 (如果它们相同,那么您就会知道您正在文件系统级别而不是文件内部查找内容。)

You can use xxd to look inside the files. Looking at the comments, you now have a working version and a non-working version, so can compare them side-by-side to understand what the problem was. (And if they are identical then you know you are looking for something at the file system level, not inside the files.)

(xxd随vi软件包一起提供,并且

(xxd comes with the vi package, and apparently is also available for Windows if you install vim.)

这里是带有和不带有UTF-8 BOM的脚本的示例输出(顺便说一句,没有区别) :这两个脚本至少在Ubuntu上的CasperJS 1.1上都有效):

Here is sample output for a script with and without the UTF-8 BOM (which, incidentally, made no difference: both these scripts worked, at least with CasperJS 1.1 on Ubuntu):

0000000: efbb bf76 6172 2063 6173 7065 7220 3d20  ...var casper = 
0000010: 7265 7175 6972 6528 2763 6173 7065 7227  require('casper'
0000020: 292e 6372 6561 7465 2829 3b0a 0a63 6173  ).create();..cas
0000030: 7065 722e 7374 6172 7428 2768 7474 703a  per.start('http:
0000040: 2f2f 676f 6f67 6c65 2e63 6f6d 2f27 2c20  //google.com/', 
0000050: 6675 6e63 7469 6f6e 2829 207b 0a20 2020  function() {.   
0000060: 2074 6869 732e 6563 686f 2874 6869 732e   this.echo(this.
0000070: 6765 7454 6974 6c65 2829 293b 0a7d 293b  getTitle());.});
0000080: 0a0a 6361 7370 6572 2e72 756e 2829 3b0a  ..casper.run();.


0000000: 7661 7220 6361 7370 6572 203d 2072 6571  var casper = req
0000010: 7569 7265 2827 6361 7370 6572 2729 2e63  uire('casper').c
0000020: 7265 6174 6528 293b 0a0a 6361 7370 6572  reate();..casper
0000030: 2e73 7461 7274 2827 6874 7470 3a2f 2f67  .start('http://g
0000040: 6f6f 676c 652e 636f 6d2f 272c 2066 756e  oogle.com/', fun
0000050: 6374 696f 6e28 2920 7b0a 2020 2020 7468  ction() {.    th
0000060: 6973 2e65 6368 6f28 7468 6973 2e67 6574  is.echo(this.get
0000070: 5469 746c 6528 2929 3b0a 7d29 3b0a 0a63  Title());.});..c
0000080: 6173 7065 722e 7275 6e28 293b 0a         asper.run();.

这篇关于CasperJS“无法加载脚本”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆