lapwinglabs / x-ray-phantom

phantom driver for x-ray.
112 stars 30 forks source link

Cant get it to work with phantomjs #10

Open kitkat14 opened 9 years ago

kitkat14 commented 9 years ago

When I am using phantomjs without xray it works great.

When I am using the example:

var phantom = require('x-ray-phantom'); var Xray = require('x-ray');

var x = Xray() .driver(phantom());

x('http://google.com', 'title')(function(err, str) { if (err) return done(err); assert.equal('Google', str); done(); })

and run it with phantomjs test.js

I get the following error:

Error: Cannot find module 'tty'

phantomjs://bootstrap.js:289 phantomjs://bootstrap.js:254 in require C:/Users/Gebruiker/node_modules/x-ray-phantom/node_modules/debug/node.js:6 C:/Users/Gebruiker/node_modules/x-ray-phantom/node_modules/debug/node.js:210 TypeError: '[object Object]' is not a function (evaluating 'require('debug')('x- ray:phantom')')

C:/Users/Gebruiker/node_modules/x-ray-phantom/index.js:5 C:/Users/Gebruiker/node_modules/x-ray-phantom/index.js:93 TypeError: 'undefined' is not a function (evaluating 'phantom.loadModule(code, t his.filename)')

phantomjs://bootstrap.js:272 phantomjs://bootstrap.js:125 phantomjs://bootstrap.js:268 phantomjs://bootstrap.js:301 phantomjs://bootstrap.js:254 in require phantest.js:2

zipzit commented 8 years ago

I'm seeing nearly the same errors.

$ phantomjs scrape.js
Error: Cannot find module 'tty'

  phantomjs://platform/bootstrap.js:299 in require
  phantomjs://platform/bootstrap.js:263 in require
  phantomjs://platform/node.js:7
TypeError: Object is not a constructor (evaluating 'require('debug')('x-ray:phantom')')

  phantomjs://platform/index.js:6
TypeError: undefined is not a constructor (evaluating 'phantom.loadModule(code, this.filename)')

  phantomjs://platform/bootstrap.js:282 in _compile
  phantomjs://platform/bootstrap.js:126 in .js
  phantomjs://platform/bootstrap.js:278 in _load
  phantomjs://platform/bootstrap.js:311 in require
  phantomjs://platform/bootstrap.js:263 in require

I can use node and x-ray to look at static webpages. I really like the x-ray interface. Unfortunately for dynamically created content, that just won't work. I'm at a loss. I'm guessing this entire module was written to take advantage of a phantomjs wrapper (sockets?) but phantomjs in its current form doesn't support?

Er, wait just a moment! does this module require https://github.com/amir20/phantomjs-node (PhantomJS integration module for NodeJS, I would call this a Bridge module..and its installed via npm install phantom) or does it require phantomjs (downloaded from http://phantomjs.org/)?? That phantomjs.org tool is not written as a node module, its a pure standalone. I'm using the pure standalone tool (per my $phantomjs scrape.js code above...)

Suggestion: What ever the right tools are, can we get a hint added to the readme.md page to tell us what's what?

stephengardner commented 8 years ago

@zipzit Did you solve this?

zipzit commented 8 years ago

Er, no.. When you hit a brick wall, turn right. I was never able to understand when I'm running Phantom as a tool (like NPM or Node) or as a module. Frankly I'm new to this game, and I got lost in the different versions of what supports what. For my project, I'm lucky in that the data I'm scraping is generated static from the server. I was hoping to write a generic tool that would allow me to scrape JavaScript deployed content on a page, and I was hoping to use this tool to gain a bit of understanding. I failed.

stephengardner commented 8 years ago

I just fixed this by installing from phantomjs.org. Add the /bin folder to your system PATH. I guess the standalone is required by the npm module. The npm module runs the "phantom" command from your PATH.

Xsmael commented 8 years ago

Can you please details how exactly you solved it ? i have similar problem, trying to run PhantomJS with a logging module (https://github.com/Xsmael/node-logger) which bin folder is did you add to the PATH ? and what is that "standalone" ?

jiawenzhang commented 7 years ago

This module has anything to do with phantomjs. If you look at its code, it uses Nightmare which uses Electron underneath. Electron is an alternative to phantoms.

Actually, Nightmare used to depend on phantomjs, but they switched to Electron.

rohmanhm commented 7 years ago

I had the same problem in here.

ashiquemohammed commented 7 years ago

Same for me .

ugurcemozturk commented 6 years ago

Same here. Trying to use with deathbycaptcha module. Gives the following errors: Error: Cannot find module 'events' phantomjs:/platform/bootstrap.js:299 in require phantomjs:/platform/bootstrap.js:263 in require phantomjs:/platform/deathbycaptcha.js:8 phantomjs:/platform/deathbycaptcha.js:165 TypeError: Object is not a constructor (evaluating 'new DeathByCaptcha("xxx", "xxx")') /phantomjs:/code/saveCaptcha.js:20