1

I'm just starting to pick up javascript and casperjs for a project that I'm doing. I'm trying to create a project that uses babyparse in it.

Currently I have babyparse.js located at C:\js\babyparse.js.

I'm having trouble including babyparse, and I've tried a couple different ways of doing it.

1) eval('C:\js\babyparse.js') - I come up with a syntax error "Invalid Character \u0008". I found this on StackOverflow, but I was unable to find the unicode character in babyparase.js.

2) require('C:\js\babyparse.js') - this just doesn't even find the right path in windows. I'm assuming that's because of the backslash pathing of windows as opposed to the regular unix forwardslash.

3) require('C:\\js\\babyparse.js') - this gets the correct path in windows, but I get the error that CasperJS couldn't find the module C:\js\babyparse.js

I feel like I've looked a lot through stackoverflow, but maybe I'm just missing something obvious. Thanks in advance for the help!

Community
  • 1
  • 1
chu
  • 21
  • 2
  • I can't reproduce your problem (CasperJS master and PhantomJS 2.0.0). Both `require('C:\\js\\babyparse.js')` and `require('C:\\js\\babyparse')` work without a problem – Artjom B. Jan 23 '16 at 13:54

2 Answers2

0

Currently I have babyparse.js located in C:\js\babyparse


require('C:\js\babyparse.js')

You've got the path wrong it seems. The correct path would be

require('C:\\js\\babyparse\\babyparse.js')

Beware that babyparse is a node.js module. It may use some of node.js native modules wich are not present in PhantomJS javascript interpreter in which case your script will break.

If you want to use csv parsing while scraping, it's definitely better to use PapaParse which is specifically designed as general-flavour javascript without dependencies, "not even jQuery".

Vaviloff
  • 16,282
  • 6
  • 48
  • 56
  • Sorry! I meant I have babyparse.js located in C:\js\babyparse.js. I'll update the original to reflect that. Thanks for catching it! I also just put papaparse.js into the same folder and tried the same thing, but it's hitting the same issue. – chu Jan 22 '16 at 13:59
  • Please provide CasperJS script sample – Vaviloff Jan 22 '16 at 14:22
0

I managed to solve the problem!

The following snippet worked for me:

var fs = require('fs');
eval(fs.read('papaparse.js'));
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
chu
  • 21
  • 2