python+Selenium+chrome构建浏览器模拟使用
liunx环境下 本人亲测有用
按命令执行:
第一步:
sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.debsudo dpkg -i google-chrome*.deb
sudo apt-get install -f
第二步:
sudo apt-get install xvfb
第三步:
sudo apt-get install unzipwget -N http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriversudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
第四步:
sudo apt-get install python-pip
sudo pip install pyvirtualdisplay selenium
安转完成了,可以写个py文件测试下:
from pyvirtualdisplay import Display
from selenium import webdriverdisplay = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Chrome()
driver.get('http://christopher.su')
print driver.title
如果将虾上面的这两行代码注释掉就会有chrome的图形界面形成:
display = Display(visible=0, size=(800, 600))
display.start()