Linux下编译Phantomjs

1、安装依赖的库

sudo apt-get install g++ flex bison gperf ruby perl \
  libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev \
  libpng-dev libjpeg-dev

2、下载、编译

wget https://bbuseruploads.s3.amazonaws.com/ariya/phantomjs/downloads/phantomjs-2.0.0-source.zip
unzip phantomjs-2.0.0-source.zip
./build.sh

然后就是等待了,一般要1个小时以上。

3、通过python调用

最新的selenium (2.45)已经支持了PhantomJS,调用非常简单:

from selenium import webdriver

driver = webdriver.PhantomJS()
driver.get('http://you url')
for tr in driver.find_elements_by_xpath(u'your xpath'):
    print tr
driver.quit()

 

Leave a Reply

Your email address will not be published. Required fields are marked *