Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var page = require('webpage').create();
- var system = require('system');
- if (system.args.length < 2) {
- console.log('Too many args');
- phantom.exit();
- }
- var addr = system.args[1];
- addr = encodeURI(addr);
- function getString() {
- return page.evaluate( function () {
- String.prototype.replaceAll = function(search, replacement) {
- var target = this;
- return target.replace(new RegExp(search, 'g'), replacement);
- };
- var result = "";
- $.each($(".product-layout > .product-thumb > .image > a.lazy"), function(a,z) {
- if ($(z).attr("href") == "http://igway.ru/пиростикер-аст-р") return;
- result += $(z).attr("href") + "\n";
- });
- return result;
- });
- }
- page.open(addr, {charset: 'cp-1251'}, function (status) {
- if (status !== 'success') {
- console.log('FAIL to load the address');
- phantom.exit();
- }
- setTimeout(function() {
- page.render('github.png');
- var string = getString();
- if(typeof string == "undefined") {
- console.log("-1");
- phantom.exit();
- }
- console.log(string);
- phantom.exit();
- }, 2000);
- });
- var page = require('webpage').create();
- var system = require('system');
- if (system.args.length < 2) {
- console.log('Too many args');
- phantom.exit();
- }
- var addr = system.args[1];
- addr = encodeURI(addr);
- var cc = system.args[2];
- function getString() {
- return page.evaluate( function (cc) {
- var title = jQuery('form[name="product"] h1').html()
- var price = jQuery('#block_price').html()
- price = price.replace(/руб\./g, " ");
- var img = jQuery('.my_foto img').attr('src')
- var desc_short = "";
- var r = jQuery(jQuery('.tabs dd')[0]).find('.tab-content').find('p');
- var i = 0;
- for (i = 0; i < r.length; i++) {
- desc_short += jQuery(r[i]).html();
- }
- desc_short = desc_short.replace(/\n/g, " ");
- jQuery(jQuery('.tabs dd')[0]).find('.tab-content').find('p').remove();
- var desc = jQuery(jQuery('.tabs dd')[0]).find('.tab-content').html()
- desc = desc.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");
- desc = desc.replace(/\n/g, " ");
- var categ = cc;
- return "CATEG:" + categ + "\nPRICE:" + price + "\nTITLE:" + title + "\nIMG:" + img + "\nDESC:" + desc + "\nDESCSHORT:" + desc_short;
- }, cc);
- }
- page.onError = function(msg, trace) {
- var msgStack = ['ERROR: ' + msg];
- if (trace && trace.length) {
- msgStack.push('TRACE:');
- trace.forEach(function(t) {
- msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
- });
- }
- //console.error(msgStack.join('\n'));
- };
- page.onLoadFinished = function() {
- var res = getString();
- if(typeof res == "undefined") {
- console.log("-1");
- phantom.exit();
- }
- console.log(res);
- phantom.exit();
- };
- page.open(addr, {charset: 'cp-1251'}, function (status) {
- if (status !== 'success') {
- console.log('FAIL to load the address');
- phantom.exit();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement