Нужен человек по написанию скриптов используя PhantomJS

600 руб.за час • безналичный расчёт, электронные деньги
21 февраля 2017, 08:46 • 1 отклик • 55 просмотров
Есть PhantomJS 2.1.1. который выполняет скрипты например phantomjs update.js Номер
Есть доски объявлений на которые нужно раскидывать объявления (инфа по объявлениям структурирована и online)
Нужен человек на написание скриптов и поддержку уже имеющихся.
Ниже пример кода , оно же тек. задание на понимание - данный скрипт грузит только 1 фото а нужно несколько

function mouseclick(element) { //расширяем возможности phantomjs, делаем новую функцию настоящего клика по элементу
// create a mouse click event
var event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, true, window, 1, 0, 0);

// send click to element
element.dispatchEvent(event);
}

var system = require('system');
var args = system.args;


var json_page = require('webpage').create();
json_page.open('http://localhost/phantom2/product' + args[1] + '.json', function () {
//var jsonSource = json_page.plainText;
//var resultObject = JSON.parse(jsonSource);
price = 22600;
o_id = 3318;
o_description = '1- комнатная квартира , г. Минск, Советская ул. , 1988 г.п., 5/5 панельный, 31/30/15/7 кв.м.';
o_rooms = '1';
space_overall = 31;
space_flat = 30;
space_living = 15;
space_kitchen = 7;
floor = 5;
number_of_floors = 5;
o_type = 'f';
land = 0;
img[0] = 'c:\1.jpeg';
img[1] = 'c:\2.jpeg';
img[2] = 'c:\3.jpeg';
img[3] = 'c:\4.jpeg';
img[4] = 'c:\5.jpeg';
city = 'Минск';
name = 'Агентство';
titl = 'Однокомнатная квартира, Советская ул. - 3318';
phone = '375293922737';
phone3 = '375238922737';
phone4 = '375238922737';
email = 'info@info.by';
street = 'Советская ул.';
contacts = 'Агентство';
year = 1988;
material = 'панельный';
balcon = 'балкон';
sanuzel = 'раздельный';
currency = 'USD';
commercial = '';
url = '';




var square_to_site;
if (space_overall === null) {
square_to_site = 1;
} else {
square_to_site = parseInt(space_overall);
}

if (resultObject.price === null) {
price=0;
console.log(price.toString());
}
if (resultObject.space_overall !== null) {
if (resultObject.space_overall.length>4) {
space_overall=Math.round(space_overall);
}
}

if (resultObject.space_flat !== null) {
if (resultObject.space_flat.length>4) {
space_flat=Math.round(space_flat);
}
}
if (resultObject.space_living !== null) {
if (resultObject.space_living.length>4) {
space_living=Math.round(space_living);
}
}
if (resultObject.space_kitchen !== null) {
if (resultObject.space_kitchen.length>4) {
space_kitchen=Math.round(space_kitchen);
}
}
var page = new WebPage();

var i = 0, inProgress = false;

page.onLoadStarted = function () {
inProgress = true;
console.log("load started");
};

page.onLoadFinished = function () {
inProgress = false;
console.log("load finished");
};

page.viewportSize = {
width: 1400,
height: 900
};
page.zoomFactor = 1;

var page_roulette;
// Use analyzing to know which url must be loaded
if (o_type == 'f') {
page_roulette = 'https://gohome.by/profile/new_ad/1';
}

/*if (o_type == 'h' || o_type == 'u') {
page_roulette = 'http://realt.by/user/cottages/edit/';
}

if (o_type == 'o') {
page_roulette = 'http://realt.by/user/offices/uoedit/';
}*/

var steps = [

function () {
//page.settings.loadImages = false;
page.open('https://gohome.by/auth', function (status) {
if (status === 'success') {
console.log('1. Page loaded');
}
});
},
function () {
page.render('gx1.jpeg', 'jpeg', 50);
},

function () {
page.evaluate(function () {
$('input[name=auth\\[login\\]]').val('info@info.by');
$('input[name=auth\\[pass\\]]').val('7788');
$('form[name=auth]').submit();

});
},
function () {
page.render('gx2.jpeg', 'jpeg', 50);
},
function () {
page.open(page_roulette, function (status) {
if (status === 'success') {
console.log(page.title);
}
});
},
function () {
page.render('gx3.jpeg', 'jpeg', 50);
},
function () {
page.injectJs('jquery.min.js');
page.evaluate(function (commercial, url, street, o_id, o_description, o_rooms, space_overall, space_flat, space_living, space_kitchen, year, material, balcon, sanuzel, currency, floor, number_of_floors, price, o_type, land, city, name, titl, phone, phone3, phone4, args, email) {
$('#select_global_region').val('1');
$('#select_region').val('2');

var district = '0';



//$('select[name=add\\[region\\]]').val(district);

if (district == '0') {
$('input[name=add\\[city\\]]').val(decodeURIComponent((city + '').replace(/\+/g, '%20')));
}
if(street == '') {
street = 'ул. Советская';
}
$('input[name=add\\[street\\]]').val(decodeURIComponent((street + '').replace(/\+/g, '%20')).toString());

if(o_type == 'f') {
// Rooms
$('select[name=add\\[room\\]]').val(o_rooms.toString()).trigger('change');
}
if(price === 0) {
} else {
$('input[name=add\\[cost\\]]').val(price.toString());
}

// Год
$('input[name=add\\[year\\]]').val((year).toString());

// Space overall
$('input[name=add\\[sq_all\\]]').val((space_overall).toString());

// Space living
$('input[name=add\\[sq_zhil\\]]').val((space_living).toString());

// Space kitchen
$('input[name=add\\[sq_kuh\\]]').val((space_kitchen).toString());

// floor
$('input[name=add\\[floor\\]]').val((floor).toString());

// number_of_floors
$('input[name=add\\[floor_all\\]]').val((number_of_floors).toString());

if(o_type == 'h') {
$('input[name=size_area]').val(parseInt(land).toString());
}


if(o_type == 'f') {

//Санузел
if (decodeURIComponent((sanuzel + '').replace(/\+/g, '%20')) == 'два санузла') {
$('select[name=add\\[is_sanuzel\\]]').val('1');
}
if (decodeURIComponent((sanuzel + '').replace(/\+/g, '%20')) == 'нет') {
$('select[name=add\\[is_sanuzel\\]]').val('1');
}
if (decodeURIComponent((sanuzel + '').replace(/\+/g, '%20')) == 'раздельный') {
$('select[name=add\\[is_sanuzel\\]]').val('1');
}
if (decodeURIComponent((sanuzel + '').replace(/\+/g, '%20')) == 'совмещенный') {
$('select[name=add\\[is_sanuzel\\]]').val('0');
}

}

if(o_type == 'o') {
if(commercial == 'rent') {
$('input.form_radio.form_radio_type_switcher#ru').trigger('click');
}
$('#property_type').val('6').trigger('change');
}

var object_description = decodeURIComponent((o_description + '').replace(/\+/g, '%20'));
var object2_description = object_description.substr(0, 3999);
$('textarea[name=add\\[description\\]]').val(object2_description);

$('input[name=add\\[email\\]]').val(decodeURIComponent((email + '').replace(/\+/g, '%20')).toString());

$('input[name=add\\[phone\\]]').val(('+'+phone).toString());
$('input[name=add\\[phone_dop\\]]').val(('+'+phone3).toString());

}, commercial, url, street, o_id, o_description, o_rooms, space_overall, space_flat, space_living, space_kitchen, year, material, balcon, sanuzel, currency, floor, number_of_floors, price, o_type, land, city, name, titl, phone, phone3, phone4, args, email);
//эта часть грузит только 1 фото нужно исправить
page.uploadFile('input[type=file]', 'items/' + img[0]);
page.uploadFile('input[type=file]', 'items/' + img[1]);
page.uploadFile('input[type=file]', 'items/' + img[2]);
page.uploadFile('input[type=file]', 'items/' + img[3]);
page.uploadFile('input[type=file]', 'items/' + img[4]);

},
function () {
page.render('gx4.jpeg', 'jpeg', 50);
},
function () {
page.evaluate(function () {
$('#validate').trigger('click');
});
},
function () {
page.evaluate(function () {
$('#ai-mypages-button').trigger('click');
});
},
function () {
page.render('gx5.jpeg', 'jpeg', 50);
}
];


setInterval(function () {
if (!inProgress && typeof steps[i] == "function") {
console.log("step " + (i + 1));
steps[i]();
i++;
}
if (typeof steps[i] != "function") {
console.log("complete!");
phantom.exit();
}
}, 10000);
});