我已经为node.js安装了MySQL,但是我的代码没有更新数据库。
我使用$output = shell_exec('awk -F, \'NR==FNR{seen[$0]++;next} ($1 in seen)\' uploads/a.txt uploads/b.txt > exports/output.txt');
在本地服务器上运行代码
要使我的node robot.js
工作该怎么办?
我在代码中做了很多更改(我不知道自己所做的所有更改)
-删除query()
-更改我的SQL代码
-在mysql.format()
robot.js
query()
database_boxy.js
/**********CONFIGURATION*********************/
var url_site = 'https://flipp.com/circulaires';
var base_url = 'https://flipp.com/circulaires';
var nom_robot = 'Circulaires';
var base_name_table_rbt = 'rapport_execution_robot';
/*******************************************/
//require
const puppeteer = require('puppeteer');
const cheerio = require('cheerio');
var mysql = require('mysql');
require('events').EventEmitter.defaultMaxListeners = 0;
var waterfall = require('run-waterfall');
var pool_boxy_bd = require('./database_boxy');
var util = require('util');
var tool = require('./tool');
var md5 = require('md5');
var dateFormat = require('dateformat');
var execPhp = require('exec-php');
waterfall([
async function (callback){
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0');
await page.setExtraHTTPHeaders({'Accept-Language': 'fr-CA, fr;q=0.9, en;q=0.8'});
await page.setViewport({ width: 1366, height: 6000});
await page.goto(url_site, {
waitUntil: 'networkidle2',
timeout: 0
});
let content = await page.content();
var $ = cheerio.load(content);
page.screenshot({path: 'digg.png', fullPage: true});
var arrayCirculaire = ['Sephora','Forever 21','Zara','Trio Hockey','Old Navy','Club Monaco','Gap','Loft','The Children Place','H&M','Hamster','Napa']
// console.log('Salut')
try{
await $('flipp-flyer-listing-item').each(function(){
for ( var i = 0, l = arrayCirculaire.length; i < l; i++ ) {
var img = $(this).find('img.flyer-thumbnail');
let nomCirculaire = '';
try{
if(img['0'].attribs.alt.indexOf(arrayCirculaire[i]) >= 0){
var lien = $(this).find('a').attr('href');
lien = 'https://flipp.com'+lien;
nomCirculaire = arrayCirculaire[i];
var query = "UPDATE rapport_execution_robot SET lien_circulaire_interactif=? WHERE nom_robot = ?";
var inserts = ['lien','nomCirculaire'];
var sql = mysql.format(query, inserts);
pool_boxy_bd.query(sql, (err,rows) => {
if(err) throw err;
console.log('Data received from Db:\n');
console.log(rows);
});
console.log('Update '+ arrayCirculaire[i])
}
}
catch(error){
throw new Error(error);
}
}
});
}
catch(error){
throw new Error(error);
}
callback(null, 'one');
await browser.close();
},
], function (err, result1) {
util.promisify(process.exit());
})
与数据库的连接正常,并且我没有任何错误消息,但是它没有更新。
谢谢!