[WTH] Imacros/javascript expert to create a Simple Script.

Status
Not open for further replies.

ChapoGuzman

BANNED
Joined
Jun 7, 2013
Messages
294
Reaction score
188
Okay I need the script to loop/replay X amount of time and ever replay/loop to cycle through a csv and check if the link exist on a page if it doesnt stop and move on to the next loop (column) in the csv, but if the link does exist to just keep running the macros as normal.

here the script I came up with but you cant do it in imacros has to be ran from javascript

Code:
VERSION BUILD=8601111 RECORDER=FXSET 
!DATASOURCE check.csv
SET !LOOP 1
SET !DATASOURCE_COLUMNS 2
set !var1 1
add !var1 {{!loop}}
SET !DATASOURCE_LINE {{!var1}}

TAB T=1
URL GOTO=http://{{!COL1}}.blogspot.com/
TAG POS=2 TYPE=A ATTR=HREF:http://{{!COL2}}.blogspot.com/
'if the link above does not exist stop macros and move on to next loop, but if link above does exist executing macros.
URL GOTO=http://google.com/
ADD !EXTRACT {{!COL2}}
SAVEAS TYPE=EXTRACT FOLDER=c:\iMacros FILE=table.csv

Reason this cant be done in regular macros is because macros doesnt allow conditional statement.

so I believe something like this will work

Code:
VERSION BUILD=8601111 RECORDER=FXSET 
!DATASOURCE check.csv
SET !LOOP 1
SET !DATASOURCE_COLUMNS 2
set !var1 1
add !var1 {{!loop}}
SET !DATASOURCE_LINE {{!var1}}

TAB T=1
URL GOTO=http://{{!COL1}}.blogspot.com/
if { 
// link below exist
   TAG POS=2 TYPE=A ATTR=HREF:http://{{!COL2}}.blogspot.com/
   URL GOTO=http://google.com/
  ADD !EXTRACT {{!COL2}}
 SAVEAS TYPE=EXTRACT FOLDER=c:\iMacros FILE=table.csv
} 
Else {
      restart Macros to cycle the next loop in csv.
};}



LOL that shows you how I know how it should work but I just aint on that level yet to do it.

I tried asking on stackoverflow but they just assume I want someone to do it for me and brushed me off which wasnt the case I was trying to learn it but it is what it is. I came to the point that this is taking to much of my time then it is worth so Im willing to pay. I can only pay $5 bucks yea I know wish I can offer more but thats all I have in paypal at the moment, but Im always doing lil work like this so im sure I will come back to your for future help/work.

anyone interested please let me know.
 
Last edited:
Brother I hate to break it to you but imacros is very limited and does not offer logic. Meaning no if then statements. Vb net is very easy for people who are new to programming. Or you could look into python. Teach your self to program and you will be much happier. Imacros, while being useful, is just not able to perform tasks that involve logic. Well good luck op!
 
Long time no see my friend???

Hey ChapGuzman what are you trying to do with that?? :cool:
 
hm...

you need to install node.js

put the script in a file and execute these commands in the same directory
Code:
npm install request
npm install line-reader
npm install cheerio


Code:
var lineReader = require('line-reader');
var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');
var http = require('http');


var max = 10;
var infile = 'check.csv';
var outfile = 'table.csv';


var running = 0;
var output = fs.createWriteStream(outfile, { encoding:'utf8'} );
http.globalAgent.maxSockets = max;

var linecb = null;
function next() {
	if ( running == max )
		return;
	if ( linecb == null ) {
		if ( running == 0 )
			output.close();
		return;
	}
	linecb();
}


lineReader.eachLine(infile, function(line,last,cb){
	var cols = line.split(',');
	linecb = cb;
	if ( last )
		linecb = null;
	
	if ( cols.length != 2 )
		next();

	++running;
	console.log('looking in',cols[0],'for',cols[1]);
	request('http://'+cols[0]+'.blogspot.com', function(error,response,body){
		--running;
		if ( error ) {
			console.log('error getting '+cols[0]+': '+error);
		} else {
			var ch = cheerio.load( body );
			ch('a[href="http://'+cols[1]+'.blogspot.com/"]').first().each( function(){
				console.log('found',cols[1] );
				output.write( cols[1]+'\n' );
			});
		}
		next();
	});
	next();
});
 
Long time no see my friend???

Hey ChapGuzman what are you trying to do with that?? :cool:

what up man, im on skype all the time hit me up whenever, im just trying to clean up a list.

hm...

you need to install http://nodejs.org/

put the script in a file and execute these commands in the same directory
Code:
npm install request
npm install line-reader
npm install cheerio


Code:
var lineReader = require('line-reader');
var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');
var http = require('http');


var max = 10;
var infile = 'check.csv';
var outfile = 'table.csv';


var running = 0;
var output = fs.createWriteStream(outfile, { encoding:'utf8'} );
http.globalAgent.maxSockets = max;

var linecb = null;
function next() {
    if ( running == max )
        return;
    if ( linecb == null ) {
        if ( running == 0 )
            output.close();
        return;
    }
    linecb();
}


lineReader.eachLine(infile, function(line,last,cb){
    var cols = line.split(',');
    linecb = cb;
    if ( last )
        linecb = null;
    
    if ( cols.length != 2 )
        next();

    ++running;
    console.log('looking in',cols[0],'for',cols[1]);
    request('http://'+cols[0]+'.blogspot.com', function(error,response,body){
        --running;
        if ( error ) {
            console.log('error getting '+cols[0]+': '+error);
        } else {
            var ch = cheerio.load( body );
            ch('a[href="http://'+cols[1]+'.blogspot.com/"]').first().each( function(){
                console.log('found',cols[1] );
                output.write( cols[1]+'\n' );
            });
        }
        next();
    });
    next();
});

Thanks for this complete setup, I installed node, install nmp in the same directory, and I run the script node <script name> and it runs through it just doesnt spit out the output in the table.csv, any idea?
 
Thanks for this complete setup, I installed node, install nmp in the same directory, and I run the script node <script name> and it runs through it just doesnt spit out the output in the table.csv, any idea?

Are you sure your table.csv file is writeable?
 
Are you sure your table.csv file is writeable?


yeah it is writable and we fixed the problem already thanks to sockpuppet who took time out of his day to help me for free, thanks I truly appreciate it (ignore my last PM I figured it out) thanks again.



THIS JOB IS CLOSED!
 
Status
Not open for further replies.
This thread has been auto closed due to the forum's thread age policy. Read more.
Back
Top