¿Cómo puedo configurar y ejecutar PhantomJS en Ubuntu?
Configuré PhantomJS y lo grabé en video: https://www.dailymotion.com/video/xnizmh_1_webcam
Instrucciones de construcción: http://phantomjs.org/build.html
¿Hay algo malo en mi configuración?
Después de configurarlo, leí el tutorial de inicio rápido y traté de escribir este código
phantomjs hello.js
Me da el error "comando no encontrado". ¿Cómo puedo resolver este problema?
25 answers
La respuesta de Guidouil me puso en el camino correcto. Tuve que añadir un enlace simbólico adicional a / usr / bin/, e hice enlaces simbólicos directos para todos los 3 - ver a continuación.
Estoy instalando en el servidor Ubuntu Natty Narwhal.
Esto es exactamente lo que hice.
cd /usr/local/share
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2
sudo tar xjf phantomjs-1.9.7-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
Y finalmente cuando lo hago
phantomjs -v
Obtengo 1.9.7
Si alguien ve algún problema con lo que he hecho, por favor hágamelo saber.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-13 08:08:04
PhantomJS está en npm. Puede ejecutar este comando para instalarlo globalmente:
npm install -g phantomjs-prebuilt
phantomjs -v
debe volver 2.1.1
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-02 04:05:27
Descargue desde el sitio web de phantomjs el paquete preconfigurado : http://phantomjs.org/download.html a continuación, abra un terminal y vaya a la carpeta de descargas
sudo mv phantomjs-1.8.1-linux-x86_64.tar.bz2 /usr/local/share/.
cd /usr/local/share/
sudo tar xjf phantomjs-1.8.1-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.8.1-linux-x86_64 /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
Entonces para comprobar instalar {[1] } debe devolver 1.8.1
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-06 22:52:23
Instalar desde el gestor de paquetes:
sudo apt-get install phantomjs
Estos son los pasos de compilación que usé (tenga en cuenta que estas instrucciones son para la versión 1.3. Ver comentarios a esta respuesta para las instrucciones de instalación de la última PhantomJS):
sudo apt-get update
sudo apt-get install git-core
sudo apt-get install build-essential
sudo apt-get install libqt4-dev libqtwebkit-dev qt4-qmake
git clone git://github.com/ariya/phantomjs.git && cd phantomjs
git checkout 1.3
qmake-qt4 && make
sudo apt-get install xvfb xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
Lanzamiento Xvfb:Xvfb :23 -screen 0 1024x768x24 &
Ahora ejecuta phantom:DISPLAY=:23 ./phantomjs hello.js
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-12 01:24:55
Para la versión de PhantomJS anterior a la 1.5, considere esto (copia literal de las instrucciones de compilación en el sitio web de phantom):
Para Ubuntu Linux (probado en una instalación de barebone de Ubuntu 10.04 Lucid Lynx y Ubuntu 11.04 Natty Narwhal):
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev git clone git://github.com/ariya/phantomjs.git cd phantomjs git checkout 1.7 ./build.sh
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-02 09:26:30
Para Ubuntu puedes usar las versiones prediseñadas descargables desde el sitio de PhantomJS.
Si tienes un tiempo serio en tus manos también puedes construirlo tú mismo. (Este es exactamente el procedimiento de la respuesta de Nikhil).
Los chicos de PhantomJS recomiendan usar los binarios para ahorrar tiempo:
Advertencia: Compilar PhantomJS desde el código fuente lleva mucho tiempo, principalmente debido a miles de archivos en el módulo WebKit. Con 4 trabajos de compilación en paralelo en una máquina moderna, todo el proceso tarda aproximadamente 30 minutos. Es muy recomendable descargar e instalar el paquete binario ya hecho si está disponible.
Con una máquina moderna significan > 4 núcleos, > 8gb mem creo. Lo probé en una instancia de micro AWS y me rendí después de 2 horas.
En resumen: instale los paquetes preconfigurados desde el sitio de PhantomJS según sus instrucciones.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-10 20:05:07
Personalmente prefiero usar npm
(ver respuesta de Arnel Bucio)
sudo npm install -g phantomjs
Pero! Me di cuenta de que algunos de npm
módulo todavía no puede verlo como ejecutable global.
So!
-
Crear nuevo
/usr/share/phantomjs/
enlace de directoriocd /usr/share sudo ln -s ../lib/node_modules/phantomjs/lib/phantom phantomjs
-
Elimina el antiguo
/usr/bin/phantomjs
enlace ejecutable y crea el nuevocd /usr/bin sudo mv phantomjs phantomjs.old sudo ln -s ../share/phantomjs .
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:10:07
En mi vagabundo bootstrap:
apt-get install -y build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
echo y | ./build.sh
ln -s /home/vagrant/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
cd ..
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-29 21:23:47
He terminado con esto.
sudo apt-get update
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
./build.sh
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-10 15:44:59
Ver enlace Guía de instalación está en ...
Y ejecutar en terminal con este comando
Phantomjs web webdriver = 4444
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-01 09:38:32
Desde el sitio oficial: phantomjs site
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.8
./build.sh
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-18 08:06:42
Para Ubuntu, descargue el archivo adecuado desde http://phantomjs.org/download.html . CD a la carpeta descargada. Entonces:
sudo tar xvf phantomjs-1.9.0-linux-x86_64.tar.bz2
sudo mv phantomjs-1.9.0-linux-x86_64 /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/bin/phantomjs
Asegúrese de reemplazar el nombre del archivo en estos comandos con el archivo que ha descargado.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-01 19:25:33
Tenga en cuenta que esta es definitivamente una manera de hacerlo:
$ sudo apt-get install phantomjs
$ phantomjs -v
1.6.0
Lamentablemente, se instala 1.6 y no la última, pero esto funciona para mis propósitos.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-05 20:00:04
Sé que esto es demasiado viejo, pero, por si acaso alguien llega a esta pregunta de Google now, puede instalarlo escribiendo apt-get install phantomjs
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-29 19:41:46
O la última versión de 32 bits de Linux
sudo wget http://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-i686.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.2-linux-i686/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.2-linux-i686/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.2-linux-i686/bin/phantomjs /usr/bin/phantomjs
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-20 19:10:07
Instalación y Llamada a Phantomjs
Seguir los pasos no funciona, pero clonado de otros construidos. (ver2.0)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-15 23:10:24
A continuación el procedimiento de instalación de Julio Napurí https://gist.github.com/julionc
Versión: 1.9.8
Plataforma: x86_64
Primero, instale o actualice el software del sistema más reciente.
sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
Instale estos paquetes necesarios para que PhantomJS funcione correctamente.
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev
Consíguelo en el sitio web de PhantomJS.
cd ~
export PHANTOM_JS="phantomjs-1.9.8-linux-x86_64"
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
Una vez descargado, mueva la carpeta Phantomjs a / usr / local / share / y cree un enlace simbólico:
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
Ahora, debería haber PhantomJS correctamente en su sistema.
phantomjs --version
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-18 07:54:48
He encontrado esta forma más sencilla - Dependencias fantasma + Npm
sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev
Y mnp
[sudo] npm install -g phantomjs
Hecho.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-08 15:51:47
En linux para ejecutar hello.js no se olvide de añadir el camino de hola.js:
Phantomjs YourPathToPhantomjsFolder/examples/hello.js
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-12 20:17:24
Si desea usar phantomjs fácilmente, puede usarlo en phantomjscloud.com Puede obtener el resultado solo mediante una solicitud http.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-22 06:48:37
En Ubuntu para Windows, encontré que ni apt-get
ni npm
las versiones funcionaron para mí. Lo que funcionó fue el script de este comentario.
Para facilitar su uso, pegué todo en un archivo de script llamado install_phantomjs.sh
, lo hice ejecutable (chmod u+x install_phantomjs.sh
), y luego lo ejecuté (./install_phantomjs.sh
)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-17 18:16:22
Así es como coloco una versión específica de phantomjs en /usr/local/bin en mis contenedores docker.
curl -Ls https://github.com/Medium/phantomjs/releases/download/v1.9.19/phantomjs-1.9.8-linux-x86_64.tar.bz2 \
| tar jxvf - --strip-components=2 -C /usr/local/bin/ ./phantomjs-1.9.8-linux-x86_64/bin/phantomjs
O sin ./
dependiendo del sistema operativo.
curl -Ls https://github.com/Medium/phantomjs/releases/download/v1.9.19/phantomjs-1.9.8-linux-x86_64.tar.bz2 \
| tar jxvf - --strip-components=2 -C /usr/local/bin/ phantomjs-1.9.8-linux-x86_64/bin/phantomjs
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-02 09:47:31
Puede ponerse en marcha sin sudo
o npm
. Simplemente descargar, extracto, y añadir a la ruta de acceso.
Esto tiene la ventaja añadida de easy backup si tiene el hábito de hacer copias de seguridad de toda su carpeta de inicio, lo que recomiendo encarecidamente. Esto también funciona con cualquier versión de Linux.
➤ cd ~
➤ wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
➤ mkdir phantomjs
➤ tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C phantomjs
➤ echo 'export PATH="$PATH:$HOME/phantomjs/bin"' >> .profile
➤ source .profile
➤ phantomjs -v
2.1.1
Las desventajas son:
- Tendrá que actualizar manualmente
- Otros usuarios no tendrán acceso a esto.
Podría usar un script de shell muy simple para instalar/actualizar
#!/bin/sh
# install_phantomjs.sh $VERSION
$VERSION = $1
printf "Downloading PhantomJS $VERSION...\n"
wget "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$VERSION-linux-x86_64.tar.bz2"
printf "Extracting PhantomJS $VERSION to ~/phantomjs...\n"
mkdir ~/phantomjs
tar xjf phantomjs-$VERSION-linux-x86_64.tar.bz2 -C ~/phantomjs
printf "Done! Make sure $HOME/phantomjs/bin is in your path.\n"
O en un Dockerfile
# Download and setup PhantomJS
ENV PHANTOMJS_VERSION 2.1.1
RUN curl -fSL "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2" -o /tmp/phantomjs.tar.bz2 && \
mkdir ~/phantomjs && \
tar xjf /tmp/phantomjs.tar.bz2 -C ~/phantomjs && \
rm /tmp/phantomjs.tar.bz2
ENV PATH /home/$USERNAME/phantomjs/bin:$PATH
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-13 15:43:38
Esto es lo que hice en mi máquina ubuntu 16.04
sudo apt-get update
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo mv path/where/you/downloaded/phantomjs /usr/bin
Y finalmente cuando lo hago
phantomjs -v
Consigo 2.1.1
Después de pasar por cada respuesta de este hilo. Creo que esta es la mejor solución para instalar y ejecutar phantomjs en ubuntu.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-29 18:52:40