1.安装chromehtml
yum install google-chromepython
2.安装chromedriver
全部版本的下载地址:https://sites.google.com/a/chromium.org/chromedriver/downloadslinux
wget https://chromedriver.storage.googleapis.com/2.39/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
3.seleniumweb
pip install selenium
4.例子chrome
>>> from selenium import webdriver >>> chrome_options = webdriver.ChromeOptions() >>> chrome_options.add_argument('--headless') >>> chrome_options.add_argument('--no-sandbox') # 这句必定要加 #我一开始没加,就一直报‘selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally’。搞了好久。 >>> driver = webdriver.Chrome(executable_path='/root/chromedriver', chrome_options=chrome_options) >>> driver.get('http://py2app.readthedocs.io/en/latest/examples.html') >>> print driver.title Example setup.py templates — py2app 0.15 documentation
5.注意api
chromedriver应该要给执行权限,也就是chmod +x chromedriver,由于我为了解决Chrome failed to start: exited abnormally这个错误,作了不少尝试,也不知道这个是否是必须的,加了不会错😄app