Using casperjs and PHP to save data

两盒软妹~` 提交于 2020-01-23 04:24:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/10710663/using-casperjs-and-php-to-save-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!