标签: phantomjs

如何使用CasperJS登录网站?

如何通过提交表格登录CasperJS.我搜索谷歌并没有找到任何关于它的好例子.

javascript phantomjs casperjs

33
推荐指数
2
解决办法
4万
查看次数

在Mac上安装PhantomJS

我正在尝试在我的Mac(Yosemite)上安装PhantomJS.

我做了以下事情:

npm install phantomjs
Run Code Online (Sandbox Code Playgroud)

然后我做了:

npm install phantomjs-prebuilt
Run Code Online (Sandbox Code Playgroud)

这两个都出现在我的node_modules中.但是当我试着奔跑时,phantomjs --version我得到了

   -bash: phantomjs: command not found
Run Code Online (Sandbox Code Playgroud)

还尝试从下载网站安装二进制文件,但没有.我错过了什么?最终目标是使用casperjs,但目前casper正在询问

Fatal: [Errno 2] No such file or directory; did you install phantomjs?
Run Code Online (Sandbox Code Playgroud)

我以为我做了......?

installation phantomjs casperjs

33
推荐指数
4
解决办法
3万
查看次数

如何从CasperJS访问iframe?

我有一个带iframe的网页.我想使用CasperJS访问iframe的内容.特别是,我需要单击按钮并填写表单.我怎样才能做到这一点?

主要网页是 main.html:

<html><body>
<a id='main-a' href="javascript:console.log('pressed main-a');">main-a</a>
<iframe src="iframe.html"></iframe>
<a id='main-b' href="javascript:console.log('pressed main-b');">main-b</a>
</body></html>
Run Code Online (Sandbox Code Playgroud)

iframe是:

<html><body>
<a id='iframe-c' href="javascript:console.log('pressed iframe-c');">iframe-c</a>
</body></html>
Run Code Online (Sandbox Code Playgroud)

我天真的做法:

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug"
});

casper.start("http://jim.sh/~jim/tmp/casper/main.html", function() {
    this.click('a#main-a');
    this.click('a#main-b');
    this.click('a#iframe-c');
});

casper.run(function() {
    this.exit();
});
Run Code Online (Sandbox Code Playgroud)

当然,这不起作用,因为a#iframe-c选择器在主框架中无效:

[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://jim.sh/~jim/tmp/casper/main.html, HTTP GET
[debug] [phantom] Navigation requested: url=http://jim.sh/~jim/tmp/casper/main.html, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "http://jim.sh/~jim/tmp/casper/main.html"
[debug] …
Run Code Online (Sandbox Code Playgroud)

javascript iframe webkit phantomjs casperjs

32
推荐指数
2
解决办法
2万
查看次数

phantomjs截图字体缺失,而是呈现的框

我在Centos 6.3上使用PhantomJs 1.8.1进行自动ui测试.测试失败时,屏幕截图会保存到文件系统中.

我的问题是,即使屏幕截图已保存,它们也不包含可读字体.

所以,如果网站的内容如下:

你好,世界!

该网站的屏幕截图如下所示:

在此输入图像描述

因此,它不是实际的字母,而是渲染和保存小盒子.

该系统是6.3.还安装了Freetype和Fontconfig.

我怎么能解决这个问题呢?

谢谢!

phantomjs

32
推荐指数
3
解决办法
2万
查看次数

phantomJS网页超时

我已经设置了一个脚本来创建我们的应用程序的webshots.它运行完美,一切正常直到我遇到一个破坏网址的图像:

 "<img src='http://testserver.our.intranet/fetch/image/373e8fd2339696e2feeb680b765d626e' />"
Run Code Online (Sandbox Code Playgroud)

我已经设法在使用下面的6秒后打破脚本,之前它只是永远循环.

但是,是否可以忽略网络请求(AKA取出图像DOM),然后继续创建没有图像的拇指,(或者注入的图像缺少图像!)

var page = require('webpage').create(),
    system = require('system'),
    address, output, size;

if (system.args.length < 3 || system.args.length > 5) {
    phantom.exit(1);
} else {
    address = system.args[1];
    output  = system.args[2];
    page.viewportSize = { width: 640, height: 640 };
    page.zoomFactor = 0.75;
    page.clipRect = { top: 10, left: 0, width: 640, height: 490 };
    try{
        page.open(address, function (status) {
            if (status !== 'success') {
                console.log('Unable to load the address!');
                phantom.exit();
            } else …
Run Code Online (Sandbox Code Playgroud)

webpage-rendering phantomjs

31
推荐指数
1
解决办法
3万
查看次数

通过单击按钮刮取网页并导航

我想在服务器端执行以下操作:

1)刮取网页
2)模拟该页面上的点击,然后导航到新页面.
3)刮掉新页面
4)模拟新页面上的一些按钮点击
5)通过json或其他东西将数据发送回客户端

我正在考虑将它与Node.js一起使用.

但我很困惑我应该使用哪个模块
a)Zombie
b)Node.io
c)Phantomjs
d)JSDOM
e)其他

我已经安装了node,io但是无法通过命令提示符运行它.

PS:我在Windows 2008服务器上工作

node.js web-scraping zombie.js jsdom phantomjs

31
推荐指数
2
解决办法
2万
查看次数

如何增加CasperJS中的超时

我在用waitFor().代码如下:

casper.waitFor(function check() {
    return this.evaluate(function() {
        return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
    });
}, function then() {
    console.log('Done');
});
Run Code Online (Sandbox Code Playgroud)

我把它作为控制台输出

Wait timeout of 5000ms expired, exiting.
Run Code Online (Sandbox Code Playgroud)

如何增加超时?

编辑:我已将代码更改为

 casper.waitFor(function check() {
        return this.evaluate(function() {
            return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
        });
    }, function then() {
        console.log('Done');
    },10000);
Run Code Online (Sandbox Code Playgroud)

它给了我以下错误:

CasperError: Invalid timeout function, exiting.
    C:/filename:1720 in _check
Run Code Online (Sandbox Code Playgroud)

javascript phantomjs casperjs

31
推荐指数
2
解决办法
3万
查看次数

TypeError:undefined不是构造函数

我对Angular很新,而且我还在努力解决这个问题.我正在使用我从Yeoman Generator生成的Angular 1.5.8编写一些测试.

具体来说,我正在试图弄清楚如何操纵$ httpBackend结果(我不确定这是否重要)...

在我的app.js文件中,我有以下代码:

.run(['$rootScope', '$location', 'breadcrumbService', function ($rootScope, $location, breadcrumbService) {
    $rootScope.$on('$viewContentLoaded', function () {
        jQuery('html, body').animate({scrollTop: 0}, 200);
    });

    $rootScope.isEditMode = false;
    $rootScope.$on('$stateChangeSuccess', function () {
        // ------------ this next line is failing -----------
        $rootScope.isEditMode = $location.path().toLowerCase().endsWith('/edit') || $location.path().toLowerCase().endsWith('/new');
    });

    $rootScope.parseJson = function (value) {
        return angular.fromJson(value);
    };

    $rootScope.bc = breadcrumbService;

    $rootScope.title = "";
}])
Run Code Online (Sandbox Code Playgroud)

大约一半的线(我添加评论的地方)失败了.具体来说,endsWith函数失败(toLower很好),出现此错误:

PhantomJS 2.1.1 (Windows 8 0.0.0) Service: breadcrumbService should return breadcrumb label in json format FAILED
        TypeError: undefined is …
Run Code Online (Sandbox Code Playgroud)

javascript phantomjs angularjs karma-jasmine

31
推荐指数
4
解决办法
4万
查看次数

PhantomJS:拨打电话时指定用户代理

我正在使用PhantomJS来调用网页,如下所示:

page.open('http://example.com', function (s) {
  console.log(page.content);
  phantom.exit();
});
Run Code Online (Sandbox Code Playgroud)

我在Drupal Simpletests的上下文中使用它,它要求我设置一个特殊的USERAGENT以便使用测试数据库而不是真正的数据库.我想获取特定用户代理的网页.例如,在使用Curl的PHP中,我可以在进行cUrl调用之前使用CURLOPT_USERAGENT执行此操作.

谢谢!

阿尔伯特

phantomjs

30
推荐指数
1
解决办法
2万
查看次数

找不到幻影

尝试在Ubuntu上使用ruby中的phantomjs时出现以下错误:

 Failure/Error: visit root_path
 Cliver::Dependency::NotFound:
   Could not find an executable ["phantomjs"] on your path.
 # ./spec/features/search_spec.rb:17:in `block (2 levels) in <top (required)>'
 # ./spec/support/vcr.rb:23:in `block (3 levels) in <top (required)>'
 # ./spec/support/vcr.rb:23:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

phantomjs在当地建造并添加到PATH.如何让红宝石找到幻影?

ruby ubuntu phantomjs

30
推荐指数
5
解决办法
2万
查看次数