现在最新版本的webdriver,不在有专门的无头模式。而是在有界面的模式中修改代码,就ok,以斗鱼为例:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
class DouYu(object):
def __init__(self):
self.start_url = "https://www.douyu.com/directory/all"
# 无头模式
self.chrome_options = Options()
self.chrome_options.add_argument('--headless')
self.chrome_options.add_argument('--disable-gpu')
self.driver = webdriver.Chrome(chrome_options=self.chrome_options)
其他的该怎么写就怎么写。