运行多个casperjs实例 [英] Running multiple instances of casperjs

查看:45
本文介绍了运行多个casperjs实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要同时运行3个url请求。我想到要运行3个casper实例,每个实例都获取一个url。
作为一个简单示例,我尝试了2个实例。

I need to run 3 url requests simultaneously.I thought of running 3 casper instances each fetching a url. As a simple example,I tried with 2 instances.

var casper=require('casper').create();
casper.start('http://www.google.com');

var casper1=require('casper').create();
casper1.start('http://www.google.com');

casper1.then(function() {
    casper1.echo('inside');
});
casper1.echo('outside');

casper1.run();
casper.run();

输出只显示'outside'。为什么不运行casper1.echo('inside' );

Output shows only 'outside'.Why does'nt it run the casper1.echo('inside');

推荐答案

CasperJS使用一堆命令,只要您使用其api中的一个函数(然后,从头开始, thenOpen等)。一旦所有项目都在堆栈中排队,就可以通过执行casper.run()依次执行它们。如果没有将某些内容添加到堆栈中,Casper将不会执行它。

CasperJS uses a stack of commands that created whenever you use one of the functions from their api (start, then, thenOpen, etc). Once all of the items are queued up in the stack, you can execute them in order by doing casper.run(). If something isn't added to the stack, Casper will not execute it.

简单地说,因为执行了casper1.echo('outside'),所以它没有被执行

Simply put, casper1.echo('outside') isn't being executed because it was never added to the stack.

他们的 FAQ 对该主题进行了更详细的分类。

Their FAQ on the topic breaks it down in more detail.

这篇关于运行多个casperjs实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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