2016-04-25 30 views

risposta

31

Ho appena installato phantomjs 2.1.1 in Ubuntu 16.04 con le seguenti fasi, che ho trovato dopo un po 'di googling:

sudo apt-get install nodejs 
sudo apt-get install nodejs-legacy 
sudo apt-get install npm 
sudo npm -g install phantomjs-prebuilt 
+6

Dal PhantomJS non ha nulla a che fare con node.js o NPM (installato solo per comodità), questo installa un intero ecosistema per un singolo binario che non ha nulla fare con l'ecosistema. –

+1

Abbastanza vero. Il nodejs (e nodejs-legacy) sono richiesti da npm per installare correttamente phantomjs. I passi che ho seguito sono stati utilizzati con il selenio in python. Il npm potrebbe sempre essere disinstallato una volta fatto.Questo era solo un modo molto veloce per far funzionare il driver PhantomJS con il selenio. – dmdip

5

Ecco come lo farei se fossi in via di sviluppo. I pacchetti sono di versione per nodejs e non ubuntu:

Uso nvm: https://github.com/creationix/nvm

touch ~/.profile 
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.7/install.sh | bash 

source ~/.profile 
# node 6x 
nvm install 6.5.0 
npm install [email protected] 

# node 4x 
nvm install 4.5.0 
nvm use 4.5.0 
npm install [email protected] 

# node 0.12x 
nvm install 0.12 
npm show [email protected]* version 
npm install [email protected] 

Forse stiamo sviluppando su 0.10, 0.12, 4.X, iojs4.x, 6.X, etc bene ora abbiamo accesso a scegliere quale versione di phantomjs:

[email protected]:~$ npm show [email protected]* version 
[email protected] '0.0.1' 
[email protected] '0.0.2' 
[email protected] '0.0.3' 
[email protected] '0.0.4' 
[email protected] '0.0.5' 
[email protected] '0.0.6' 
[email protected] '0.0.7' 
[email protected] '0.0.8' 
[email protected] '0.0.9' 
[email protected] '0.1.0' 
[email protected] '0.1.1' 
[email protected] '0.2.0' 
[email protected] '0.2.1' 
[email protected] '0.2.2' 
[email protected] '0.2.3' 
[email protected] '0.2.4' 
[email protected] '0.2.5' 
[email protected] '0.2.6' 
[email protected] '1.9.8' 
[email protected] '1.9.9' 
[email protected] '1.9.10' 
[email protected] '1.9.11' 
[email protected] '1.9.12' 
[email protected] '1.9.13' 
[email protected] '1.9.15' 
[email protected] '1.9.16' 
[email protected] '1.9.17' 
[email protected] '1.9.18' 
[email protected] '1.9.19' 
[email protected] '2.1.1' 
[email protected] '2.1.2' 
[email protected] '2.1.3' 
[email protected] '1.9.20' 
[email protected] '2.1.7' 

sistema per scenari di implementazione, ecc.

Ecco come utilizzare il tarball

export PHANTOM_JS_VERSION=2.1.1 
wget "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2" 
tar xvfj "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2" 
ln -sf "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64/bin/phantomjs" "/usr/bin" 

testato su Ubuntu 14.04, forse spostare la cartella in un'altra posizione diversa da ./

aggiornamento per 16.04:

wget può o non può lavorare vedi: https://github.com/Medium/phantomjs/issues/161

# install dependencies 
sudo apt-get install libfontconfig 
# extract the tar file 
tar xvfj "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2" 
# use full path 
ln -sf "$(pwd)/phantomjs-$PHANTOM_JS_VERSION-linux-x86_64/bin/phantomjs" "/usr/bin" 

Errore

phantomjs: errore durante il caricamento librerie condivise: libfontconfig.so.1: non può aprire il file oggetto condiviso: Nessun file o directory

Prova:

sudo apt-get install libfontconfig 
+0

Non funziona su Ubuntu 16.04 – 3zzy

+0

@ 3zzy hai ragione, aggiornato sembrava un problema di dipendenza, e il collegamento a un percorso relativo potrebbe essere stato un problema. Anche per qualsiasi ragione 'wget' non funzionava quindi ho' scp' la pallina di catrame sulla macchina. Aggiunto problema github con lo stesso errore negato 403 acess. – jmunsch

1

Per coloro che hanno problemi di installare come me

è più facile di quanto si pensi ...

  • I disinstallare phantomjs: Rimuovere phantomjs da Ubuntu sudo apt-get remove phantomjs o rimuovere la cartella NPM di /node_modules/phantomjs sarà in /, forse sarà necessario rimuovere ln il link del phantomjs in /usr/bin o /usr/local/bin/ il nome di esso è phantomjs

Esempio

//use this if you installed with apt-get 
sudo apt-get remove phantomjs *remove the phantomjs 
rm /usr/bin/phantomjs   *use this if the link didn't remove. 

//use this if you installed from npm: like this: npm install phantomjs 
rm -R /node_modules/phantomjs *note: it will be in other folder, search it. 
  • installare phantomjs da NPM: npm install phantomjs da / directory, NPM installarlo nella cartella /node_module/phantomjs

Esempio

cd /; 
npm install phantomjs 
  • file bin test

Esempio

//check version of phantomjs 
/node_modules/phantomjs/bin/phantomjs -v 
/node_modules/phantomjs/bin/phantomjs test.js 
  • link file bin a /usr/bin:

Esempio

ln -sf /node_modules/phantomjs/bin/phantomjs /usr/bin/phantomjs

  • versione controllo di esso per vedere se è ok
    phantomjs -v nel mio caso 2.1.1
5

Quindi, la risposta di jmunsch funziona per me, ma solo per fornire una chiara e minimale ricetta:

export PHANTOM_JS_VERSION=2.1.1 

sudo apt-get install libfontconfig 

wget "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2" 

tar xvfj "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2" 

ln -sf "$(pwd)/phantomjs-$PHANTOM_JS_VERSION-linux-x86_64/bin/phantomjs" "/usr/bin" 

L'ultima riga richiede sudo a causa di/usr/bin, ma si può mettere il link simbolico da nessuna parte ...

1

phantomjs 2.1.1 è attualmente fornito in bundle con 16.04 (https://launchpad.net/ubuntu/xenial/+source/phantomjs), quindi è possibile installarlo/aggiornarlo come pacchetto di sistema.

Update: esiste questa risposta per scopi informativi, ma è sconsigliato di utilizzare la versione del pacchetto di sistema ora a causa di problemi quali: https://bugs.launchpad.net/ubuntu/+source/phantomjs/+bug/1605628 Questo è legato a un problema con il caricamento di file che è stato fissato a monte, ma la la natura della correzione gli impediva di funzionare come un pacchetto di sistema.

L'opzione migliore corrente è utilizzare il binario precompilato da: https://bitbucket.org/ariya/phantomjs/download