IT박스

Ubuntu에서 PhantomJS를 어떻게 설정하고 실행할 수 있습니까?

itboxs 2020. 6. 1. 19:29
반응형

Ubuntu에서 PhantomJS를 어떻게 설정하고 실행할 수 있습니까?


PhantomJS를 설정하고 비디오에 녹화했습니다 : https://www.dailymotion.com/video/xnizmh_1_webcam

빌드 지침 : http://phantomjs.org/build.html

설정에 문제가 있습니까?

설정 후 빠른 시작 자습서를 읽고이 코드를 작성하려고했습니다.

phantomjs hello.js 

"명령을 찾을 수 없음"오류가 발생합니다. 이 문제를 어떻게 해결할 수 있습니까?


귀두 일의 대답은 저를 올바른 길로 안내했습니다. / usr / bin /에 심볼릭 링크를 하나 더 추가해야했으며 3에 대해 직접 심볼릭 링크를 수행했습니다 (아래 참조).

우분투 서버 Natty Narwhal에 설치하고 있습니다.

이것이 바로 내가 한 일입니다.

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

그리고 마침내 내가 할 때

phantomjs -v

나는 1.9.7을 얻는다

내가 한 일에 문제가 있으면 알려주세요.


PhantomJS는 npm에 있습니다. 이 명령을 실행하여 전역으로 설치할 수 있습니다.

npm install -g phantomjs-prebuilt  

phantomjs -v 돌아와야한다 2.1.1


phantomjs 웹 사이트에서 사전 빌드 된 패키지 ( http://phantomjs.org/download.html) 를 다운로드 한 다음 터미널을 열고 Downloads 폴더로 이동하십시오.

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

설치를 확인하려면 phantomjs -v반환해야합니다1.8.1


패키지 관리자에서 설치하십시오.

sudo apt-get install phantomjs

내가 사용한 빌드 단계는 다음과 같습니다 (이 지침은 버전 1.3 용입니다. 최신 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

이제 Xvfb를 설치하십시오

sudo apt-get install xvfb xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic

Xvfb 시작 :
Xvfb :23 -screen 0 1024x768x24 &

이제 팬텀을 실행하십시오.
DISPLAY=:23 ./phantomjs hello.js


1.5 이상의 PhantomJS 버전의 경우 다음 사항을 고려하십시오 (phantom 웹 사이트의 빌드 지시 사항 사본).

Ubuntu Linux (Ubuntu 10.04 Lucid Lynx 및 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

Ubuntu의 경우 PhantomJS 사이트에서 다운로드 할 수있는 사전 빌드 된 버전을 사용할 수 있습니다 .

당신이 당신의 손에 심각한 시간이 있다면 당신은 또한 그것을 직접 만들 수 있습니다 . (이것은 Nikhil의 답변에서 나온 절차입니다).

PhantomJS에있는 사람들은 바이너리를 사용하여 시간을 절약 할 것을 권장합니다.

경고 : 소스에서 PhantomJS를 컴파일하는 데는 오랜 시간이 걸립니다. 주로 WebKit 모듈의 수천 개 파일 때문입니다. 최신 머신에서 4 개의 병렬 컴파일 작업을 수행하면 전체 프로세스에 약 30 분이 소요됩니다. 기성 바이너리 패키지가 제공되는 경우 다운로드하여 설치하는 것이 좋습니다.

현대식 기계를 사용하면 4 코어 이상, 8GB mem 이상이라고 생각합니다. 마이크로 AWS 인스턴스에서 시도하고 2 시간 후에 포기했습니다.

한마디로 : PhantomJS 사이트에서 사전 구축 된 패키지를 지침에 따라 설치하십시오.


내가 선호하는 성격 npm( Arnel Bucio 답변 참조 )

sudo npm install -g phantomjs

그러나! 일부 npm모듈은 여전히 ​​전역 실행 파일로 볼 수 없습니다.

여기에 이미지 설명을 입력하십시오

그래서!

  • /usr/share/phantomjs/디렉토리 링크 만들기

    cd /usr/share
    sudo ln -s ../lib/node_modules/phantomjs/lib/phantom phantomjs
    
  • 이전 /usr/bin/phantomjs실행 가능 링크를 제거 하고 새 링크를 작성하십시오

    cd /usr/bin
    sudo mv phantomjs phantomjs.old
    sudo ln -s ../share/phantomjs .
    

내 방랑자 부트 스트랩에서 :

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 ..

나는 이것을했다.

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

설치 안내서의 링크를 참조하십시오 ...

https://gist.github.com/julionc/7476620

그리고이 명령으로 터미널에서 실행하십시오.

phantomjs --webdriver = 4444


공식 사이트에서 : 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

Ubuntu의 경우 http://phantomjs.org/download.html 에서 적절한 파일을 다운로드 하십시오 . 다운로드 한 폴더에 CD를 넣습니다. 그때:

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

Make sure to replace the file name in these commands with the file you have downloaded.


Be aware this is definitely one way to do it:

$ sudo apt-get install phantomjs
$ phantomjs -v
1.6.0

Sadly, it installs 1.6 and not the latest one, but this works for my purposes.


I know this is too old, but, just i case someone gets to this question from Google now, you can install it by typing apt-get install phantomjs


Or the latest - 32bit version 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

Installation and Calling Phantomjs

Follow the steps doesn't work, but cloned from others built. (ver2.0)


Bellow the installation procedure by Julio Napurí https://gist.github.com/julionc

Version: 1.9.8

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev

Install these packages needed by PhantomJS to work correctly.

sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev

Get it from the PhantomJS website.

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

Once downloaded, move Phantomjs folder to /usr/local/share/ and create a symlink:

sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin

Now, It should have PhantomJS properly on your system.

phantomjs --version

I have found this simpler way - Phantom dependencies + 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

and npm

[sudo] npm install -g phantomjs

Done.


On linux to run hello.js don't forget to add the path of hello.js:

phantomjs YourPathToPhantomjsFolder/examples/hello.js


If you want to use phantomjs easily, you can use it at phantomjscloud.com You can get the result just by http request.


On Ubuntu for Windows, I found neither apt-get nor npm versions worked for me. What worked was the script from this comment.

For ease of use, I pasted the whole thing into a script file called install_phantomjs.sh, made it executable (chmod u+x install_phantomjs.sh), and then ran it (./install_phantomjs.sh)


This is how I place a specific version of phantomjs in /usr/local/bin on my docker containers.

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

or with out ./ depending on OS.

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

You can get up and running without sudo or npm. Simply download, extract, and add to path.

This has the added advantage of easy backup if you are in the habit of backing up your entire home folder which I highly recommend. This also works with any version of 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

The disadvantages are:

  1. You will need to manually upgrade
  2. Other users will not have access to this.

You could use a very simple shell script for installing/upgrading

#!/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"

Or in a 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

Here is what I did on my ubuntu 16.04 machine

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

and finally when I do

phantomjs -v

I get 2.1.1

After going through every answer of this thread. I think this is the best solution for installing and running phantomjs in ubuntu.

참고 URL : https://stackoverflow.com/questions/8778513/how-can-i-setup-run-phantomjs-on-ubuntu

반응형