Selenium Webdriver .get() 没有打开窗口 - 没有错误

我正在尝试使用硒打开谷歌。当我运行它时,控制台中不会出现任何错误,但是不会打开 chrome 窗口。程序简单地终止。当我在 Chrome 78 上时,我在上一个项目中使用了几乎相同的代码(并且它有效)。它使用的是版本 80。


from selenium import webdriver

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By

from selenium.webdriver.common import action_chains, keys

from multiprocessing import Pool, cpu_count, freeze_support

import os

import time



PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

DRIVER_BIN = os.path.join(PROJECT_ROOT, "chromedriver-80-mac")


def get_driver():

    options = webdriver.ChromeOptions()

    options.add_argument('--headless')

    driver = webdriver.Chrome(executable_path=DRIVER_BIN, options=options)

    return driver


def test():

    driver = get_driver()

    driver.get('https://www.google.com')

    time.sleep(3)

    driver.quit()


test()


侃侃无极
浏览 255回答 1
1回答

RISEBY

您已指定无头环境,这意味着您不会看到窗口。如果你想看到一个窗口,删除这行代码:options.add_argument('--headless')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python