CASPERJS 加密
CASPERJS Crypto
我的 casperjs 脚本有问题。我试图在 SQL 中插入数据,但我有两条错误消息:
Error: Cannot find module crypto
我尝试了 npm install crypto
但这并没有改变任何东西。
我试图检索nodejs的json以在casper中传递它,它不起作用。
第二个错误信息是:
TypeError: Object is not a constructor (evaluating' new Connection
({config: new ConnectionConfig (config)})")".
我的脚本:
var fs = require('fs');
var casper = require('casper').create({
verbose: true,
logLevel: 'error',
pageSettings: {
loadImages: true,
loadPlugins: true,
clientScripts: ["../libs/jquery.min.js"]
},
onDie: function () {
console.log('Page is died');
},
onPageInitialized: function () {
console.log("Page Initialized");
}
});
casper.on('remote.message', function (msg) {
this.echo('remote message caught: ' + msg);
});
casper.on("page.error", function (msg, trace) {
this.echo("Page Error: " + msg, "ERROR");
});
var url_connexion = 'https://accounts.zoho.eu/signin?servicename=ZohoCRM&signupurl=https://www.zoho.eu/crm/lp/signup.html';
var credentials = {email: "*******@gmail.com", password: "******"};
var identifiant = {input_email: 'input[name="lid"]', input_password: 'input[name="pwd"]', valider_connexion: '#signin_submit'};
var result = [];
var x = require('casper').selectXPath;
casper.start(url_connexion, function() {
console.log('start1');
console.log("*************************");
console.log(" Page de connexion chargee");
console.log("*************************");
casper.wait(5000, function(){
casper.capture("./screenshots/step_1.png");
console.log('premier_screen')});
this.sendKeys(identifiant.input_email, credentials.email);
this.sendKeys(identifiant.input_password, credentials.password);
casper.wait(5000, function(){
casper.capture("./screenshots/step_2.png");
console.log('second_screen')});
casper.thenClick(identifiant.valider_connexion, function(){
casper.wait(5000, function(){
casper.capture("./screenshots/step_3.png");
console.log('troisieme_screen');
});
});
});
casper.then(function(){
console.log('ATTENTIONNNNNNNE');
var myparameters = {Url:"https://crm.zoho.com/crm/ShowTab.do?module=Invoices"};
casper.wait(5000, function(){
casper.thenOpen('https://crm.zoho.com/crm/ShowTab.do?module=Invoices', function(){
console.log("step_cap");
casper.capture("./screenshots/step_4.png");
});
});
});
casper.then(function(){
console.log('NEWWWW');
var myparameters = {Url:"https://crm.zoho.com/crm/EntityInfo.do?module=Invoices&id=2957002000000136328"};
casper.wait(5000, function(){
casper.thenOpen('https://crm.zoho.com/crm/EntityInfo.do?module=Invoices&id=2957002000000136328', function(){
console.log("step_cap");
casper.capture("./screenshots/step_5.png");
casper.then(Extract_data_on_page);
});
});
});
function Extract_data_on_page(){
console.log('extract_data');
var zoho_result_identifiant =
{
result_id:'//*[@id="subvalue_INVOICENUMBER"]'
};
var result_intermediaire = {name :""};
result_intermediaire.name = this.fetchText('tr#detailViewButtonLayerDummyTableRow #subvalue_INVOICESUBJECT');
result= [];
result.push(result_intermediaire);
casper.then(function(){
console.log('***********************');
console.log(result[0].name);
console.log(result[0]);
console.log(result);
console.log(result_intermediaire);
console.log('***********************');
});
}
casper.then(function(){
var mysql = require('mysql');
console.log("start_bdd");
var con = mysql.createConnection({
user: 'root',
password: '*****',
host: 'localhost',
database: 'zoho_first'
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO Factures (Titre) VALUES ('Company Inc')";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});
});
casper.run();
CasperJS 和 PhantomJS 与 node.js 不兼容(尽管 some npm packages may work if they don't depened在节点的内部模块上并且不使用 ES6)。
因此,您无法从 CasperJS 直接 将数据保存到 MySQL。幸运的是还有其他选择:
你可以用你知道的语言构建一种中间人脚本,它可以从 CasperJS 接收数据并将其放入 MySQL。您可以通过 HTTP 或 CLI 向其发送数据。例如,它可以是本地主机上等待 POST 请求的简单 PHP 脚本。
您可以使用 PhantomJS fs
模块以 SQL 格式保存数据,然后生成一个 MySQL 进程以通过 child process 模块导入它
我的 casperjs 脚本有问题。我试图在 SQL 中插入数据,但我有两条错误消息:
Error: Cannot find module crypto
我尝试了 npm install crypto
但这并没有改变任何东西。
我试图检索nodejs的json以在casper中传递它,它不起作用。
第二个错误信息是:
TypeError: Object is not a constructor (evaluating' new Connection ({config: new ConnectionConfig (config)})")".
我的脚本:
var fs = require('fs');
var casper = require('casper').create({
verbose: true,
logLevel: 'error',
pageSettings: {
loadImages: true,
loadPlugins: true,
clientScripts: ["../libs/jquery.min.js"]
},
onDie: function () {
console.log('Page is died');
},
onPageInitialized: function () {
console.log("Page Initialized");
}
});
casper.on('remote.message', function (msg) {
this.echo('remote message caught: ' + msg);
});
casper.on("page.error", function (msg, trace) {
this.echo("Page Error: " + msg, "ERROR");
});
var url_connexion = 'https://accounts.zoho.eu/signin?servicename=ZohoCRM&signupurl=https://www.zoho.eu/crm/lp/signup.html';
var credentials = {email: "*******@gmail.com", password: "******"};
var identifiant = {input_email: 'input[name="lid"]', input_password: 'input[name="pwd"]', valider_connexion: '#signin_submit'};
var result = [];
var x = require('casper').selectXPath;
casper.start(url_connexion, function() {
console.log('start1');
console.log("*************************");
console.log(" Page de connexion chargee");
console.log("*************************");
casper.wait(5000, function(){
casper.capture("./screenshots/step_1.png");
console.log('premier_screen')});
this.sendKeys(identifiant.input_email, credentials.email);
this.sendKeys(identifiant.input_password, credentials.password);
casper.wait(5000, function(){
casper.capture("./screenshots/step_2.png");
console.log('second_screen')});
casper.thenClick(identifiant.valider_connexion, function(){
casper.wait(5000, function(){
casper.capture("./screenshots/step_3.png");
console.log('troisieme_screen');
});
});
});
casper.then(function(){
console.log('ATTENTIONNNNNNNE');
var myparameters = {Url:"https://crm.zoho.com/crm/ShowTab.do?module=Invoices"};
casper.wait(5000, function(){
casper.thenOpen('https://crm.zoho.com/crm/ShowTab.do?module=Invoices', function(){
console.log("step_cap");
casper.capture("./screenshots/step_4.png");
});
});
});
casper.then(function(){
console.log('NEWWWW');
var myparameters = {Url:"https://crm.zoho.com/crm/EntityInfo.do?module=Invoices&id=2957002000000136328"};
casper.wait(5000, function(){
casper.thenOpen('https://crm.zoho.com/crm/EntityInfo.do?module=Invoices&id=2957002000000136328', function(){
console.log("step_cap");
casper.capture("./screenshots/step_5.png");
casper.then(Extract_data_on_page);
});
});
});
function Extract_data_on_page(){
console.log('extract_data');
var zoho_result_identifiant =
{
result_id:'//*[@id="subvalue_INVOICENUMBER"]'
};
var result_intermediaire = {name :""};
result_intermediaire.name = this.fetchText('tr#detailViewButtonLayerDummyTableRow #subvalue_INVOICESUBJECT');
result= [];
result.push(result_intermediaire);
casper.then(function(){
console.log('***********************');
console.log(result[0].name);
console.log(result[0]);
console.log(result);
console.log(result_intermediaire);
console.log('***********************');
});
}
casper.then(function(){
var mysql = require('mysql');
console.log("start_bdd");
var con = mysql.createConnection({
user: 'root',
password: '*****',
host: 'localhost',
database: 'zoho_first'
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO Factures (Titre) VALUES ('Company Inc')";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});
});
casper.run();
CasperJS 和 PhantomJS 与 node.js 不兼容(尽管 some npm packages may work if they don't depened在节点的内部模块上并且不使用 ES6)。
因此,您无法从 CasperJS 直接 将数据保存到 MySQL。幸运的是还有其他选择:
你可以用你知道的语言构建一种中间人脚本,它可以从 CasperJS 接收数据并将其放入 MySQL。您可以通过 HTTP 或 CLI 向其发送数据。例如,它可以是本地主机上等待 POST 请求的简单 PHP 脚本。
您可以使用 PhantomJS
fs
模块以 SQL 格式保存数据,然后生成一个 MySQL 进程以通过 child process 模块导入它