Phantomjs 负责渲染解析JavaScript,Selenium负责驱动浏览器与Python对接,Python负责做后期处理.
[下载地址]
解压:
tar xjvf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /opt
链接:
cd /opt/phantomjs-2.1.1-linux-x86_64
ln -s /opt/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
pip3 install Selenium
####安装chrome驱动
[下载地址]
解压到/opt
链接:
sudo ln -s /opt/chromedriver /usr/bin/chromedriver
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://www.baidu.com')
elem = browser.find_element_by_name('wd')
elem.send_keys(u"搜索测试")