简体   繁体   English

使用casperjs和PHP保存数据

[英]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. 我想做的是使用casperjs自动化我在网站上创建帐户的过程。 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. 如果我不需要使用PHP来做到这一点,那也很好。 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. 您还可以返回任何补充信息的JSON序列化,以简化PHP脚本对它们的使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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