centos7+python+selenium+chrome

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

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息