无废话,先安装辅助包

yum install -y openssl-devel.x86_64 bzip2-devel.x86_64 sqlite-devel.x86_64 readline-devel.x86_64  

然后下载Python2.7.3编译安装

wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2  
tar jxvf Python-2.7.3.tar.bz2  
cd Python-2.7.3  
./configure --prefix=/usr/local/python2.7.3
make  
make install  

安装pip利器:

wget https://bootstrap.pypa.io/get-pip.py  
/usr/local/python2.7.3/bin/python get-pip.py

安装selenium

/usr/local/python2.7.3/bin/pip install selenium

安装PhantomJS

npm install -g phantomjs  

最后修改下PATH

export PATH=/usr/local/python2.7.3/bin:$PATH  

搞定。

来段小程序测一下:

from selenium import webdriver  
from selenium.webdriver.common.keys import Keys

driver = webdriver.PhantomJS(service_args=['--ssl-protocol=any'])  
driver.implicitly_wait(10)  
driver.get('http://www.python.org/')  
assert "Python" in driver.title  
elem = driver.find_element_by_name("q")  
elem.send_keys("pycon")  
elem.send_keys(Keys.RETURN)  
assert "No results found." not in driver.page_source  
print(driver.title)  
driver.quit()  
comments powered by Disqus