use options instead of chrome_options 問題的解決

使用 selenium能夠調用 google、firebox等瀏覽器進行爬蟲的爬取,但當我運行:python

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=chrome_options)

driver.get("http://www.cip.cc/")

的時候出現了這樣的問題:web

E:\pycharm\project_PaChong\venv\Scripts\python.exe E:/pycharm/project_PaChong/test_1.py
E:/pycharm/project_PaChong/test_1.py:27: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(chrome_options=chrome_options)

對,當我試圖將代碼換成 無瀏覽器模式 執行時,出現了這個警告;雖然不影響執行,但強迫症的我仍是想解決它。chrome

 

【DeprecationWarning: use options instead of chrome_options】 ---> 【警告:使用選項而不是chrome_options】瀏覽器

 

看這句話的翻譯能夠大概猜想出,此參數是已經棄用的,應該是被新的參數替換了;less

一番搜索後找到了替換此參數的參數;ide

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(options=chrome_options)

driver.get("http://www.cip.cc/")

對,將 chrome_options 替換爲 options 便可。google

相關文章
相關標籤/搜索