please help me how to read this csv in casperjs

151 views
Skip to first unread message

Santosh Maruwada

unread,
Mar 2, 2017, 8:09:12 AM3/2/17
to CasperJS
I have an excel sheet with 10-20 links of websites.
Now I want to make a script which reads each link and searches for it over the netI'm using this code but it's not working..
Can someone please help.

var fs = require('fs');

casper.start(casper.cli.get(0));

casper.then(function() {

        f = fs.open('KwenchPOI.csv','r');

        for(i = 0; i < 10; i++) {

                var a=f.readLine();

                casper.start('a', function() {

                        this.echo(this.fetchText('p'));

                });

        }

        f.close(); 

 });

casper.run();


philippe....@oscaro.com

unread,
Mar 6, 2017, 6:03:28 AM3/6/17
to CasperJS
Hello Santosh Maruwada,

I wrote a quick script for you (tested and validated on my side).

var casper = require('casper').create();
var links = [];

casper
.start();

casper
.then(function() {

   
var fs = require('fs');

   
var i = 0;
   
    stream
= fs.open('./data/KwenchPOI.csv', 'r');
    line
= stream.readLine();
   
   
// import data from csv file into the array
   
while(line) {
        links
[i] = line;
        line
= stream.readLine();
        i
++;
   
}

    stream
.close();
    casper
.echo('\n'+i+' lines read from KwenchPOI.csv file\n');
});

casper
.then(function() {
   
// loop on array
    casper
.each(links, function(self, link) {
        casper
.echo(link);
   
});
});

casper
.run();

I hope it will help you :)

Usage:
casperjs script.js


Reply all
Reply to author
Forward
0 new messages