鱼C论坛

 找回密码
 立即注册
查看: 3936|回复: 2

关于Phantomjs的一些问题 求帮助

[复制链接]
发表于 2016-11-27 18:39:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
首先我下载好了压缩包phantomjs 解压了并添加了环境变量
命令行中输入 phantomjs -v   显示2-1-1
说明安装成功的

第①个问题:
我写了一个js文件  名字是 hello.js   内容如下:
console.log('Hello, world!');
phantom.exit();

我在windows命令行中输入
phantomjs C:\Users\Administrator\Desktop\hello.js         注(C:\Users\Administrator\Desktop\     这是我桌面路径)
它输出  hello world!
这是可以的
但是  我如果不输路径就报错
它报   Can't open  'hello.js'  错误   这是什么原因我用python打开文件  也是差不多输 python hello.py  就能打开   这是我环境变量设置少了吗

第2个问题:
还有一个如果我先进到phantomjs里面   就是说我在命令行中输入phantomjs
然后命令行就变成 phantomjs>的样子了   
然后输入C:\Users\Administrator\Desktop\hello.js   或者是hello.js
他报错 1n.jpg       该怎么解决

第3个问题:
我运行页面加载和屏幕捕获两个程序   获取不到图片  代码如下:
var page = require('webpage').create();
page.open('http://cuiqingcai.com', function (status) {
    console.log("Status: " + status);
    if (status === "success") {
        page.render('example.png');
    }
    phantom.exit();
});
输出 为status :success
但是没图片
这个是屏幕捕捉   也没图片
var page = require('webpage').create();
//viewportSize being the actual size of the headless browser
page.viewportSize = { width: 1024, height: 768 };
//the clipRect is the portion of the page you are taking a screenshot of
page.clipRect = { top: 0, left: 0, width: 1024, height: 768 };
//the rest of the code is the same as the previous example
page.open('http://cuiqingcai.com/', function() {
  page.render('germy.png');
  phantom.exit();
});
这个输出没

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-11-27 18:58:48 | 显示全部楼层
本帖最后由 ppp111 于 2016-11-27 19:10 编辑

第一个问题我搞明白了  是我没有进入要运行的目录   我先cd到我要打开的目录就OK了
即在命令行样子为    C:\Users\Administrator\Desktop>  的情况下   我可以  phantomjs hello.js     主要是好久没按了  有点忘了

告诉大家一个小窍门  按住shift 右击鼠标  可以快速进入该目录的命令行(选在此处打开命令行)   妈妈再也不担心我一个一个目录的打了

那么第2个问题  我在命令行中输入phantomjs   就变为 phantomjs>   此时不管输 hello.js  还是  路径加hello.js   都不行了
有大牛知道原因吗?   是不是 输入 phantomjs   直接进到该 niu览器   所以输命令没用了

第3个问题  我暂时还没找到  不知道是不是那个代码有问题  

大家有关phantomjs的问题也可以提出来  一起想想看解决一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-11-27 19:54:14 | 显示全部楼层
第三个问题的原因也找到了 好高兴啊    代码没问题  就是   那个网址有问题   那个网页博主  把博客弄得太好了  一些图片的转动啊什么的   ajax动态的什么  加载太久  截不出图来    换个百度主页什么的   一下就保存下来了  
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-24 05:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表