详细的介绍如下:
转载:https://www.jianshu.com/p/3e4241085490
运行Selenium + PhantomJS ,会有下列提示:
UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless ’
新版的 selenium已经放弃PhantomJS改用 Chrome headless
可以使用下列代码去掉chrome 界面化
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
browser = webdriver.Chrome(r'D:\chromedriver_win32\chromedriver.exe',chrome_options=chrome_options)
运行chrome 会提示:
DeprecationWarning: use options instead of chrome_options
—>如果要去掉警告提示,把chrome_options修改成 options:
建议这样改 browser = webdriver.Chrome(r’D:\chromedriver_win32\chromedriver.exe’,options=chrome_options
此时通过 chrome_options 选项来添加定制的Chrome 来选项参数,
但是此时一直提示“DeprecationWarning: use options instead of chrome_options warnings.warn(‘use options instead of chrome_options’, DeprecationWarning)“
根据错误提示阅读了下源码 :
if chrome_options:
warnings.warn('use options instead of chrome_options', DeprecationWarning)
options = chrome_options
if options is None:
# desired_capabilities stays as passed in
if desired_capabilities is None:
desired_capabilities = self.create_options().to_capabilities()
else:
if desired_capabilities is None:
desired_capabilities = options.to_capabilities()
else:
desired_capabilities.update(options.to_capabilities())