python selenium centos_centos7+python+selenium+chrome

1.安装chrome

yum install google-chrome

wget https://chromedriver.storage.googleapis.com/2.39/chromedriver_linux64.zip

unzip chromedriver_linux64.zip

3.selenium

pip install selenium

4.例子

>>> 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.注意

chromedriver应该要给执行权限,也就是chmod +x chromedriver,因为我为了解决Chrome failed to start: exited abnormally这个错误,做了很多尝试,也不知道这个是不是必须的,加了不会错

你可能感兴趣的:(python,selenium,centos)