使用casperjs和PHP保存数据 [英] Using casperjs and PHP to save data

查看:87
本文介绍了使用casperjs和PHP保存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找有关如何执行此操作的教程或示例,但要么我不了解该解决方案就在我的鼻子底下,要么没人真正将其解决. >

我想做的是使用casperjs自动化我在网站上创建帐户的过程.我将提供一些不同的用户名,然后在最后输出一个文件,其中包含用于注册的用户名和密码.

如果我不需要使用PHP来做到这一点,那也很好.我很困惑.感谢您的帮助.

解决方案

不确定要完全理解您的问题(请参阅我在上面的评论),但基本上是:

var casper = require('casper').create();
var username = 'foo';
var password = 'bar';

casper.start('http://service.domain.tld/register.html', function() {
    this.fill('form[action="/register"]', {
        'username': username,
        'password': password
    }, true);
});

casper.then(function() {
    if (/Your account was created/.test(this.fetchText('.success'))) {
        this.echo('Created account: ' + username + '/' + password);
    } else {
        this.echo('Failed creating account for ' + username);
    }
});

casper.run();

您还可以返回所有补充信息的JSON序列化信息,以简化PHP脚本对它们的使用.

I've been looking for some kind of tutorial or example on how to do this, but either I'm not understanding that the solution is right under my nose, or no one has really put this out there.

What I'm trying to do is use casperjs to automate a process where I create an account on a website. I will be providing a few different user names, and then I want to output a file at the end with the username that was used for registration along with the password.

If I don't need to use PHP to do this, that's fine as well. I'm just very confused. Thanks for the help.

解决方案

Not sure to fully understand your question (see my comment above it), but basically:

var casper = require('casper').create();
var username = 'foo';
var password = 'bar';

casper.start('http://service.domain.tld/register.html', function() {
    this.fill('form[action="/register"]', {
        'username': username,
        'password': password
    }, true);
});

casper.then(function() {
    if (/Your account was created/.test(this.fetchText('.success'))) {
        this.echo('Created account: ' + username + '/' + password);
    } else {
        this.echo('Failed creating account for ' + username);
    }
});

casper.run();

You could also return some JSON serialization of any supplementary information to ease their consumption by a PHP script.

这篇关于使用casperjs和PHP保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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