var request = require("request");
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'mysql',
port: 3307
});
connection.connect();
request("https://www.zhouheiya.cn/wcs/Tpl/home/default/storejson/store.json", function (error, response) {
var newArr = [];
var arr = JSON.parse(response.body);
for (var index = 0; index < arr[0].children.length; index++) {
for (var jj = 0; jj < arr[0].children[index].children.length; jj++) {
for (var gg = 0; gg < arr[0].children[index].children[jj].children.length; gg++) {
newArr.push(arr[0].children[index].children[jj].children[gg].level);
}
}
}
for (var i = 0; i < newArr.length; i++) {
request("https://www.zhouheiya.cn/wcs/Tpl/home/default/storejson/" + newArr[i] + ".json", function (error, response) {
var dataArr = JSON.parse(response.body);
for (var j = 0; j < dataArr.length; j++) {
var addSql = 'INSERT INTO heiya(id,x,y,name,pos) VALUES(0,?,?,?,?,?)';
var addSqlParams = [dataArr[j][0], dataArr[j][1], dataArr[j][2], dataArr[j][3]];
connection.query(addSql, addSqlParams, function (err, result) {
if (err) {
console.log('[INSERT ERROR] - ', err.message);
return;
}
console.log('----INSERT----');
});
}
})
}
})
网友评论