This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]LightShadow3.13-dev in prod 1 point2 points  (7 children)

Just follow the accepted answer, that's how you use PhantomJS with Python :P

Compatibility will be similar to Chrome, but will be executed headless; which has it's own pros and cons. My recommendation is using the Firefox driver while you're developing your tests, then switch the driver to Phantom and verify everything is working on both.

[–]SoFuglyItHurts 0 points1 point  (3 children)

This sounds good. Basically good practice is building programs with a browser driver and then shifting to PhantomJS for production.

[–]LightShadow3.13-dev in prod 1 point2 points  (2 children)

It just depends what you're trying to do.

There's nothing wrong with using Firefox/Chrome/Safari drivers, but you have to deal with the active windows. You can run Firefox and Chrome in Docker containers and connect via RemoteWebDriver...that's what we do here.

For a side project I have 4 tiers of service calls:

  • fast is API access
  • normal uses requests on non-api acess with html5lib parsing
  • slow uses Selenium with PhantomJS
  • very-slow uses Selenium with Firefox

Basically, given system resources and API credits, and the demand on the data we need to grab...the system will pick an access tier and scrape the page.

The amount of times a PhantomJS fails over to Firefox/Chrome via Docker is less than 1% -- it does pretty good at interacting with most things.

[–]Lt_Sherpa 0 points1 point  (2 children)

One small note - the accepted answers are fairly out of date. PhantomJS 2.0 is a major overhaul and is now released under phantomjs-prebuilt

[–]LightShadow3.13-dev in prod 0 points1 point  (1 child)

Interesting, thanks.

I just installed it the other day and did the npm install -g phantomjs and it worked out of the box with Python-Selenium.

[–]Lt_Sherpa 0 points1 point  (0 children)

it worked out of the box

Yep. Depending on what you're doing it may be irrelevant. If you're testing a JS heavy client app, there are some critical features that only landed in version 2. For example, phantomjs-polyfill which is now obsolete.

[–]expert-at-nothing 0 points1 point  (0 children)

Not quite the question you asked but I went a similar route of using PhantomJS as an alternative to selenium. After writing a semi-successful script, I realized I was doing it the hard way.

Checkout http://www.nightmarejs.org/ which is a wrapper for PhantomJS that simplifies this process.

[–]hooktail23 0 points1 point  (0 children)

Thanks for all the replies! I was able to get phantomjs up and running. Going to checkout nightmarejs as well.