使用 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