centos7+python+selenium+chrome


1.安裝chrome

yum install google-chrome

2.安裝chromedriver
所有版本的下載地址:https://sites.google.com/a/chromium.org/chromedriver/downloads

 
        
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這個錯誤,做了很多嘗試,也不知道這個是不是必須的,加了不會錯😄

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM