简体   繁体   中英

Using casperjs and PHP to save data

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM