【发布时间】:2021-10-08 18:17:55
【问题描述】:
我可以使用以下标志成功加载我的 chrome 配置文件:
user-data-dir 和 profile-directory,但是一旦加载配置文件并且 chrome 窗口实际上是打开的,就不会出现任何网页。它只是卡在一个空白屏幕上。
当我删除配置文件的代码时,它实际上能够打开存储在login-url 变量中的网页。
尝试更新到最新版本的 chrome (94.0.4606.81),我还使用here 列出的确切步骤来确保我拥有正确的 chrome 驱动程序版本。
我还做了很明显的事情,比如确保没有任何 chrome 实例在后台运行。
代码如下:
import os
from os.path import exists
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
headless = False
login_url = "https://google.com)"
def startChrome():
global headless
try:
chrome_options = Options()
if headless:
chrome_options.add_argument("--headless")
chrome_options.add_argument("----user-data-dir=C:/Users/ERIK/AppData/Local/Google/Chrome/User Data")
chrome_options.add_argument("--profile-directory=Profile 1")
global driver
driver = webdriver.Chrome(path+"/chromedriver.exe", options=chrome_options)
except:
print("Failed to start Chrome!")
input()
exit()
startChrome()
driver.get(login_url)
input()
【问题讨论】:
-
那里有一个错字... login_url = "google.com)" 可能会干扰 url 验证。
标签: python selenium google-chrome selenium-chromedriver