selenium
模块是python爬虫经常用到的一个模块,最近在使用的时候总是会在控制台中弹出一些
[25592:10576:0203/182407.361:ERROR:device_event_log_impl.cc(211)] [18:24:07.361] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: 连到系统上的设备没有发挥作用。 (0x1F)
[25592:10576:0203/182407.361:ERROR:device_event_log_impl.cc(211)] [18:24:07.362] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: 连到系统上的设备没有发挥作用。 (0x1F)
类似于这样的提示,这给我们调试带来了一定的烦恼,该问题的解决方法如下:
from selenium import webdriver
# 实例化一个option对象
option = webdriver.ChromeOptions()
# 隐藏chrome浏览器的窗口(该步骤可忽略)
option.add_argument('headless')
# 关闭一些无用的输出(主要是该步骤)
option.add_experimental_option("excludeSwitches", ['enable-automation','enable-logging'])
# 在webdriver中传入option对象
wb = webdriver.Chrome(chrome_options=option)
# 然后就不会弹出上述提示了
wb.get('https://blog.mapo.cc')