使用Selenium加载Chrome已有用户配置文件时网页持续加载无法完成的问题求助
使用Selenium加载Chrome已有用户配置文件时网页持续加载无法完成的问题求助
大家好,我最近在用Python结合Selenium做个小脚本,想调用Chrome的已有用户配置文件打开浏览器,结果遇到了个头疼的问题:浏览器能正常启动,也确实加载了我指定的用户配置,但是当我尝试访问像YouTube这类网站时,页面就一直卡在加载状态,完全无法完成加载。
我把自己的代码贴在下面,麻烦各位帮我看看哪里可能出问题了:
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options # ChromeDriver的路径 chrome_driver_path = r"C:\Users\msi\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe" # Chrome用户配置文件的路径 user_profile_path = r"C:\Users\msi\AppData\Local\Google\Chrome\User Data" profile_directory = "Profile 6" # 配置Chrome选项 chrome_options = Options() chrome_options.add_argument(f"user-data-dir={user_profile_path}") chrome_options.add_argument(f"profile-directory={profile_directory}") # 关闭"Chrome正由自动测试软件控制"的提示栏 chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) chrome_options.add_experimental_option("useAutomationExtension", False) # 启动Chrome驱动 service = Service(executable_path=chrome_driver_path) driver = webdriver.Chrome(service=service, options=chrome_options) # 打开YouTube driver.get("https://www.youtube.com")
我已经尝试关闭了自动化控制的提示条,但还是没解决问题。有没有朋友遇到过类似的情况?求指点一下可能的解决方向,谢谢啦!
内容来源于stack exchange
相关产品推荐
相关产品推荐

